问题
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
回答1:
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
回答2:
$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
来源:https://stackoverflow.com/questions/40547752/how-to-compare-dates-and-strings-in-php