I need to check if two strings I have are dates and if they are the same date. They come in different formats i.e.
DD-MM-YYYY and YYYY-MM-DD
I did something that works but looks cumbersome and was wondering if there was something more succint and clever
if ((substr($old, 0, 4) == substr($new, 6, 4) && substr($old, 5, 2) == substr($new, 3, 2) && substr($old, 8, 2) == substr($new, 0, 2) && strlen($new)==10 && strlen($old) == strlen($new) && strtotime($old) == strtotime($new))) {
As unlikey as it is, we could have literally the text "DD-MM-YYYY" and YYYY-MM-DD" but obviously they aren't dates but it would still pass the test
UPDATE
if ((strtotime($old)===strtotime($new) && DateTime::createFromFormat('Y-m-d', $old) !== FALSE && DateTime::createFromFormat('d-m-Y', $new) !== FALSE)) {