Date validation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux