Decoding a date string

I have some old data which contains dates as strings and I’d like to fix it. Plus, filter any new data that may show up this way.

Let’s use the date January, 12 2000 as our date. In the strings it may show up as 01-12-2000, or 2000-12-01, or 12-01-2000, etc… Are there any available functions to parse those strings and correctly break the date into yyyy,mm,dd?

If both the month and day component have values below 13, it’s not possible to distinguish which is which. strtotime() will make a guess, but a wrong answer may not be acceptable to you. But, otherwise a simple explode() will work.

I figured as much. Thanks! :slight_smile:

If it helps for future work, strtotime uses slashes for mm/dd/yyyy and dashes for dd/mm/yyyy

Here’s the list:

mm/dd/yyyy - 02/01/2003  - strtotime() returns : 1st February 2003
mm/dd/yy   - 02/01/03    - strtotime() returns : 1st February 2003
yyyy/mm/dd - 2003/02/01  - strtotime() returns : 1st February 2003
dd-mm-yyyy - 01-02-2003  - strtotime() returns : 1st February 2003
yy-mm-dd   - 03-02-01    - strtotime() returns : 1st February 2003
yyyy-mm-dd - 2003-02-01  - strtotime() returns : 1st February 2003