Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 245
scraly Avatar asked Oct 17 '25 00:10

scraly


1 Answers

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
    }
like image 128
fin1te Avatar answered Oct 18 '25 18:10

fin1te



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!