27 Jun
2006
27 Jun
'06
3:58 a.m.
On 6/26/06, Jason Dolan
I'm looking to take a string and convert it to a date. The only problem is the string can be one of many patterns. i.e. ("%Y%m%d", "%Y-%m-%d", "%d/%m/%Y", etc...). It is also possible that the given string will fail all pattern matches, and thus return false.
What I did was to manually parse the date, and accept the input only if exactly one of the possible parsings produced a valid date. There's probably an easier way out there, but my way works for me. As Jeff points out, the "%Y%m%d" vs "%d/%m/%Y" detection will be ... interesting, to say the least. Dale