I need to pass a DATETIME value via a GET request and verify that the date received is in the proper format and is valid. I figured that on the sending end I would convert the DATETIME value using UNIX_TIMESTAMP to make it easy to validate on the receiving end, then convert it back to DATETIME via FROM_UNIXTIME.
Otherwise it appears that on the receiving end I would need to use a regex to validate the DATETIME format and then check the date is valid with checkdate(). This seems like it must be a common issue so I am wondering if there is a way to do it that does not involve this conversion.
The
DateTimeclass constructor accepts valid datetime strings. If it’s passed an invalid datetime it throws an exception. Once you have the DateTime object, you can format it in any way you want usingDateTime::format