What about using this:

$date = DateTime::createFromFormat("Y-m-d", "2011-05-20");

João Cândido de Souza Neto

"Geoff Lane" <ge...@gjctech.co.uk> escreveu na mensagem 
> Hi All,
> I'm scratching my head trying to remember how I validated string
> representation of dates 'the first time around' with PHP (before going
> over to ASP/VBScript for almost a decade). I have a feeling that I
> must have rolled my own validation function, because I can't find
> anything other than strtotime() and checkdate() in PHP itself.
> Although checkdate() seems fine, strtotime() appears to be 'broken'.
> It seems where possible to return a timestamp that makes some sense
> rather than return FALSE when handed an invalid date. For example,
> strtotime('30 Feb 1999') returns 920332800, which is equivalent to
> strtotime('02 Mar 1999'). When I ask a user to enter a date and they
> make a typo, forget that September only has 30 days, etc., I want to
> be able to detect the problem rather than post a date in the following
> month!
> It also seems that where the DateTime class uses string representation
> of dates, times, or intervals that these must be 'in a format accepted
> by strtotime()'; which implies that 'under the hood' strtotime() is
> used to convert the string to a date/time value, which implies that
> the Date/Time class cannot properly handle string input values.
> This seems to be such a common requirement that I suspect I've missed
> something basic. I'd thus be grateful for any pointers as to how to
> properly validate user-input string representation of dates.
> Cheers,
> -- 
> Geoff Lane

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

Reply via email to