开发者

PHP Compare two dates in format 2011-05-16T09:39:14+0000 (facebook datetime format)

开发者 https://www.devze.com 2023-03-06 13:47 出处:网络
In PHP开发者_运维问答 I want to compare 2 dates in this format:2011-05-16T09:39:14+0000 $datedeb=\"2011-05-18T01:25:18+0000\";

In PHP开发者_运维问答 I want to compare 2 dates in this format: 2011-05-16T09:39:14+0000

$datedeb="2011-05-18T01:25:18+0000";
$datefin="2011-05-16T09:39:14+0000";

I have PHP5.1.6 for your information.


You can use PHP's strtotime function. This converts them into the timestamps, which means you can compare them like normal numbers

    $datedeb = strtotime("2011-05-18T01:25:18+0000"); 
    $datefin = strtotime("2011-05-16T09:39:14+0000");

    if ($datedeb > $datefin) {
        //$datedeb is larger (later) than $datefin
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消