PHP 5.3.3.
$olddate = '2014-04-30';
$newdate = '30/05/2014';
Is there a simple way to compare these dates (which one is more recent) without having to manipulate the strings or changing one strings format?
I'm looking for a one or two liner?
PHP 5.3.3.
$olddate = '2014-04-30';
$newdate = '30/05/2014';
Is there a simple way to compare these dates (which one is more recent) without having to manipulate the strings or changing one strings format?
I'm looking for a one or two liner?
You can not compare values as string.
You can use \DateTime object or convert this times to integer (timestamp), and next compare.
$oldDate = \DateTime::createFromFormat('Y-m-d', $oldDate);
$newDate = \DateTime::createFromFormat('d/m/Y', $newDate);
if ($newDate > $oldDate) {
// Your action
} else {
// Your action
}