'How do I know in Magento if a given date is today / tomorrow / some day ago?

I would like to check, if a date is a today, tomorrow, yesterday, or Previous. But my code doesn't work.

public function istimedate($timestamp=''){
      $timestamp=date_create($timestamp);
      $date = strtotime(date($timestamp,"Y-m-d"));
      $current_Time = strtotime(date("Y-m-d"));

      if($date == $current_Time) { 
          $day_time = 'Today';
      } elseif(strtotime("-1 day", $date) == $current_Time) {
          $day_time = 'Yesterday';
      } elseif(strtotime("+1 day", $date) == $current_Time) {
          $day_time = 'Tomorrow';
      } else {
          $day_time = 'Someday ago';
      }
      return $day_time; 
    }
$day = $this->istimedate('2021-01-01 09:33:04');


Solution 1:[1]

A date can be converted to the proper format using $date = strtotime(date_format($timestamp,"Y-m-d")); instead of $date = strtotime(date($timestamp,"Y-m-d"));.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TylerH