Check if timestamp is today

后端 未结 7 968
傲寒
傲寒 2020-12-29 19:28

I\'ve got a timestamp in the following format (Which can easily be changed thanks to the beauties of PHP!).

2011-02-12 14:44:00

7条回答
  •  青春惊慌失措
    2020-12-29 19:51

    I prefer to compare timestamps (rather then date strings), so I use this to check today.

    $dayString = "2011-02-12 14:44:00";
    $dayStringSub = substr($dayString, 0, 10);
    
    $isToday = ( strtotime('now') >= strtotime($dayStringSub . " 00:00") 
              && strtotime('now') <  strtotime($dayStringSub . " 23:59") );
    

    Fiddle: http://ideone.com/55JBku

提交回复
热议问题