LMSouq
php-dev Open

Correctly determine if date string is a valid date in that format

MA
Marty Wallace
1 month ago
3 views
Problem Description
I'm receiving a date string from an API, and it is formatted as `yyyy-mm-dd`. I am currently using a regex to validate the string format, which works ok, but I can see some cases where it could be a correct format according to the string but actually an invalid date. i.e. `2013-13-01`, for example. Is there a better way in PHP to take a string such as `2013-13-01` and tell if it is a valid date or not for the format `yyyy-mm-dd`?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base