I want to format a date for SQL, but I am getting an unexpected result:
echo date('Y-m-d H:i:s', strtotime("February 13 2022 10:08 PM")); //2022-02-13 22:08:00
echo date('Y-m-d H:i:s', strtotime("March 23 2022 00:20 AM")); //1970-01-01 00:00:00
How can I correctly parse these dates?
This is because
strtotime("March 23 2022 00:20 AM")returns FALSE, because it is an invalid date as OMi Shah pointed out. And apparentlyFALSEbeing evaluated as0bydate()function, try printdate('Y-m-d H:i:s', FALSE);and see for yourself, it would print1970-01-01 03:00:00same asdate('Y-m-d H:i:s', 0);