如何以正确的方式在php中比较日期

如何以正确的方式在php中比较日期,php,wordpress,date,if-statement,comparison,Php,Wordpress,Date,If Statement,Comparison,我正试着比较两次约会。当日期相同时,我不希望显示结束日期。出于某种原因,这种比较不起作用。日期显示为短代码 这是我的密码: add_shortcode('tribe-start-date', 'tribe_start_date_shortcode'); function tribe_start_date_shortcode() { global $post; $start_date = tribe_get_start_date( $post->ID, false, 'd.m.Y'

我正试着比较两次约会。当日期相同时,我不希望显示结束日期。出于某种原因,这种比较不起作用。日期显示为短代码

这是我的密码:

add_shortcode('tribe-start-date', 'tribe_start_date_shortcode');
function tribe_start_date_shortcode() {
  global $post;
  $start_date = tribe_get_start_date( $post->ID, false, 'd.m.Y' );
  return $start_date;
}

add_shortcode('tribe-end-date', 'tribe_end_date_shortcode');
function tribe_end_date_shortcode() {
  global $post;
  $end_date = tribe_get_end_date( $post->ID, false, 'd.m.Y' );
  if ($start_date != $end_date) {
    return (' - ' . $end_date );
  }
} 

output:
01.10.2020 - 01.10.2020

这两个函数之间不共享
$start\u date
,因此在第二个函数中使用它时,它始终为空。您可以在调用函数时将其作为参数传入。在比较日期时,最好使用unix时间戳-