简体   繁体   中英

#php compare two times with strtotime parse function doesn't work

I am struggling with comparing two times.

$t1 = "55:10.01";
$t2 = "11.2";

$res = strtotime($t1) > strtotime($t2);
print($t1.' > '.$t2.' = '.($res?'TRUE':'FALSE'));

And the result is FALSE. If I understand correctly, PHP documentation says that both strings $t1 and $t2 should be parsed by strtotime, but... :)

Any idea what am I doing wrong? :)

try

$t1 = "55:10.01";
$t2 = "11.2";
if (date($t1) > date($t2)){
  $res = 'true';
}else{
  $res = 'false';
}
print($t1.' > '.$t2.' = '.$res);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM