Edoardo Edoardo - 23 days ago 4
PHP Question

How to compare dates and strings in PHP

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

Answer

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

Comments