How to compare two dates in php and echo newer one?
My dates are in the following format: date("F j, Y, g:i a"); which give us August 12, 2011, 9:45 am.
My dates are as follow:
- date 1
$created - date 2
$updated/ if no updated have been made value is0000-00-00 00:00:00
Any suggestion much appreciated.
But note, that
0000-00-00 00:00:00is a valid input forDateTime(), but will not work as expected. It will result in a-0001-11-30 00:00:00(at least for PHP 5.3-VC9-nts on Win7 x64).Update: I see two options for workarouning that
0000-00-00 00:00:00DEFAULT 0000-00-00 00:00:00.$updated == '0000-00-00 00:00:00'and if so, just return$created:Check if
$updated == ''(empty string) and if so return$created:I doubt that it’s right behaviour to show
0000-00-00 00:00:00for a record that was never updated.