I have a bunch of excel documents I am extracting dates from. I am trying to convert these to a standard format so I can put them in a database. Is there a function I can throw these strings at and get a standard format back? Here is a small sample of my data:
The good thing is I know it is always Month/Day
10/02/09
07/22/09
09-08-2008
9/9/2008
11/4/2010
03-07-2009
09/01/2010
I’d like to get them all into MM/DD/YYYY format. Is there a way I can do this without trying each pattern against the string?
result
Edit 1
And Edit 2 : taking account of the information on
'{0:0>2}'.format(day)from JBernardo, I added a 4th solution, that appears to be the fastestresult
The mixing solution is interesting because it combines the speed of my solution and the ability of the regex of Tim Pietzcker to detect dates in a string.
That’s still more true for the solution combining Tim’s one and the formating with
{:0>2}. I cant’ combine{:0>2}with mine becauseregx.split(date.strip())produces year with 2 OR 4 digits