如何在 PHP 中比较日期和字符串

2022-01-25 00:00:00 string date compare php

我正在开发一个 PHP 程序,我必须比较 date 变量和 string 变量.我试过 strcmp 但它不起作用......建议?谢谢

i'm developing a PHP program and i must compare a date variable and a string variable. I've tried strcmp but it doesn't work... suggests? Thank's

推荐答案

比较日期的最佳方法是使用时间戳:

Best way of comparing dates is using time-stamps :

$string = '11/05/2016';//string variable
$date = date('Y-m-d',time());//date variable

$time1 = strtotime($string);
$time2 = strtotime($date);
if($time1>$time2){
    //do this
}
else{
    //do this
}

希望对你有帮助

相关文章