3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Check dates $curDateTime = time(); //$oldDateTime = $customerLock[0]['change_date']; <== obtained from the DB $oldDateTime = 1443530876;//This is the output from the above one, just for this Example. $dateObj = new DateTime(); $date1 = $dateObj->createFromFormat('H:i:s d/m/Y', Date('H:i:s d/m/Y', $curDateTime)); $date2 = $dateObj->createFromFormat('H:i:s d/m/Y', Date('H:i:s d/m/Y', $oldDateTime)); $unix_to_date = Date('H:i:s d/m/Y', $oldDateTime); //to check the valid timestamp var_dump($unix_to_date); //outputs: string(19) "14:47:56 29/09/2015" var_dump($date1); //outputs: object(DateTime)#3 (3) { ["date"]=> string(26) "2015-09-30 12:31:54.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } //valid object as it's the currentDate earlier set. var_dump($date2); //outputs: object(DateTime)#4 (3) { ["date"]=> string(26) "2015-09-30 12:32:54.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } //Which is wrong as it's the current date time. ?>
Output for 5.4.30 - 5.4.45, 5.5.14 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.0 - 7.3.1
string(19) "14:47:56 29/09/2015" object(DateTime)#2 (3) { ["date"]=> string(26) "2015-09-30 12:45:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#3 (3) { ["date"]=> string(26) "2015-09-29 14:47:56.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.0 - 5.4.29, 5.5.0 - 5.5.13
string(19) "14:47:56 29/09/2015" object(DateTime)#2 (3) { ["date"]=> string(19) "2015-09-30 12:45:25" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#3 (3) { ["date"]=> string(19) "2015-09-29 14:47:56" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }

preferences:
61.12 ms | 408 KiB | 5 Q