how to compare date and time in php/ mysql

后端 未结 2 1906
情书的邮戳
情书的邮戳 2021-01-03 09:28

i need to compare date and time in php/mysql basically i have an application and a server the application needs to connect to the server to check new entries into the databa

相关标签:
2条回答
  • 2021-01-03 09:33

    Just comparing two timestamps would suffice:

    $t1 = strtotime($time);
    $t2 = strtotime($Max_Time);
    
    if($t1 > $t2) { .. }
    
    0 讨论(0)
  • 2021-01-03 09:49

    Why don't you create two DateTime objects and compare these?

    Like:

    $A = new DateTime(); 
    $A->setTimestamp(strtotime($time));
    
    $B = new DateTime(); 
    $B->setTimestamp(strtotime($Max_Time)); 
    
    if ($A > $B) echo "You use if statements to compare"
    
    0 讨论(0)
提交回复
热议问题