views:

102

answers:

3

Hi,

I want to parse a date and change the format using python. Date has the format like 'Mon Feb 15 2010' and i want to change the format into '15/02/2010'. Any one can help me.

Thanks in advance. Nimmy

+2  A: 

datetime module could help you with that:

datetime.datetime.strptime(date_string, format1).strftime(format2)
SilentGhost
datetime.datetime(Mon Feb 15 2010, "%a %b %d %Y").strftime("%d/%m/%Y")Is it correct ? but i got an error.
Nimmy
@nimmyliji: You saw the "string" part, right?
Ignacio Vazquez-Abrams
@nimmyliji: it was fixed 10 minutes before you posted your comment. and of course you should have `date_string` as a string.
SilentGhost
A: 

use datetime library http://docs.python.org/library/datetime.html look up 9.1.7. especiall strptime() strftime() Behavior¶ examples http://pleac.sourceforge.net/pleac_python/datesandtimes.html

Roman A. Taycher
for the error above nimmyliji you should have donedatetime.datetime.strptime("Mon Feb 15 2010", "%a %b %d %Y").strftime("%d/%m/%Y")it gives '15/02/2010'
Roman A. Taycher
Thanks a lot...
Nimmy
+2  A: 
>>> from_date="Mon Feb 15 2010"
>>> import time                
>>> conv=time.strptime(from_date,"%a %b %d %Y")
>>> time.strftime("%d/%m/%Y",conv)
'15/02/2010'
ghostdog74
Thanks a lot...
Nimmy