Re: Date validation
| From: | Geoff Lane | Date: | Fri, 20 May 2011 15:29:43 +0000 |
| Subject: | Re: Date validation | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-312972@lists.php.net to get a copy of this message | ||
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.
--
Geoff