-1

I am trying to compare previous date with today which is May 1st, but turns out that previous date is higher than today. I wonder why is this happened and how to solve it?

PHP

$api_date = '2021-04-28T06:30:00Z';
$previous_date = date('d-m-Y , H:i', strtotime($api_date));
$today_date = date('d-m-Y , H:i');

if($previous_date <= $today_date)
    print_r('true');
else{
    print_r('false'); //will return this, why?
}
LearnProgramming
  • 814
  • 1
  • 12
  • 37

1 Answers1

1

solution: just change the date format to year-month-day, thx to @Nigel Ren

$api_date = '2021-04-28T06:30:00Z';
$previous_date = date('Y-m-d , H:i', strtotime($api_date));
$today_date = date('Y-m-d , H:i');

if($previous_date <= $today_date)
    print_r('true'); //will return this
else{
    print_r('false');
}
LearnProgramming
  • 814
  • 1
  • 12
  • 37