How to compare dates and strings in PHP

和自甴很熟 提交于 2019-12-01 18:58:38

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
}

I hope it helps

Ronak
$time = strtotime('10/16/2003');

$newformat = date('Y-m-d',$time); //my date format is Y-m-d,usw your date format

there $newformat variable also a date

this way you can compare date and string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!