On Friday, May 20, 2011, Peter Lind wrote:

> Try:

> $date = new DateTime($date_string_to_validate);
> echo $date->format('Y-m-d');

Many thanks. Unfortunately, as I mentioned in my OP, the DateTime
class seems to be 'broken' for my purposes because it uses strtotime()
to convert input strings to date/time. Rather than fail when presented
with an invalid date, strtotime() returns the 'best fit' if possible.
This can be seen from:

$date = new DateTime('30 Feb 1999');
echo $date->format('Y-m-d');

which results in "1999-03-02" even though 30 Feb is an invalid date.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to