Fix Python – Parse date string and change format


Asked By – Nimmy

I have a date string with the format ‘Mon Feb 15 2010′. I want to change the format to ’15/02/2010’. How can I do this?

Now we will see solution for issue: Parse date string and change format


datetime module could help you with that:

datetime.datetime.strptime(date_string, format1).strftime(format2)

For the specific example you could do

>>> import datetime
>>> datetime.datetime.strptime('Mon Feb 15 2010', '%a %b %d %Y').strftime('%d/%m/%Y')

This question is answered By – SilentGhost

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0