Php – How to check if a string is a valid DATE, TIME or DATETIME

datetimeMySQLPHPvalidation

When I try to put a value into a DATE field which is invalid, MySQL seems to use 0000-00-00 instead. Is there a way I can do this "check" without updating a DATE field? And to do it from for example PHP?

Like, is there a way I can query the MySQL server and ask "Hey, is this DATE, TIME or DATETIME valid to you?"

Or is there maybe an even better way of doing it?

Best Answer

I use this syntax in my Application and it's work like charm!

SELECT DATE('2013-09-31') AS valid;

My System is Win7x64 with PHP 5.5 and MySQL 5.6.16