I want to convert date from one format to another.Let’s say, I have some date:
February 27, 1820
April 3, 1885
And I want to convert it:
27 February 1820
3 April 1885
I tried but getting error:
dt = "February 12, 1809"
dt = datetime.strptime('%d %b %Y')
Any kind of help will be greatly appreciated.
Yesterday, I learned from Kirk Strauser that strptime()) is much more slower than other solutions: see this file
So my advice is to use another way. For exemple:
Edit 1
The speed of the program can be improved using regx.sub(repl,ss) with repl() being a function that doesn’t extract the month and day as group(1) and group(2), but by slicing:
result
PS: I also knew that there is a problem of span of time covered by strftime and strptime (not before 1900) , that’s why I immediately choosed to treat the problem with a regex. People find regexes too heavy and impressive to resort to them, but I don’t understand this trend, because as soon as you master just a little the regexes, you can do plenty of things, with efficiency and speed. Hura for the regex tool.