I need to import text files from various sources that will contain dates in various formats. Given how many messed up pieces of data I have encountered in the test files I have gathered so far, I have decided to force the user to enter their date format before importing the file, e.g. MMDDYYYY
or DD.MM.YYYY
etc.
I can't expect these users to understand enough to enter Y-m-d
or n/j/Y
formats which would be easy enough to parse, and I can't rely on "standards" like "if a dash is used, then month comes before day", etc., so automatic parsing is very much out of the question.
The other issue with the usual PHP date formatting is that I can't predict if any date format will have single or double digits, and I don't know how createFromFormat
would parse this if I give them a single digit when it expects a double digit...
So my first thought is to start by separating pure numeric dates from others and force the user to enter a full 8 digit date along with the format code - otherwise it becomes messy. But that's as far as I've gotten so far...
I thought about parsing date and format string side by side, but that again would cause issues with one-digit numbers if I'm not careful.
I haven't found anything that'll help in my case, but maybe I'm taking this from the wrong angle - maybe there's a Javascript or jQuery date format selection tool out there that's compatible with the PHP date formats...
Any suggestions on the best approach for this?