Showing posts with label convert date yyyymmdd mm/dd/yyyy python datetime format. Show all posts
Showing posts with label convert date yyyymmdd mm/dd/yyyy python datetime format. Show all posts

Wednesday, July 16, 2014

How to convert date formats from YYYYMMDD to MM/DD/YYYY

YYYYMMDD2MM-DD-YYYY
In [1]:
from datetime import datetime
In [2]:
oldformat = '20140716'
datetimeobject = datetime.strptime(oldformat,'%Y%m%d')
In [3]:
newformat = datetimeobject.strftime('%m-%d-%Y')
print newformat
07-16-2014

In [4]:
newformat2 = datetimeobject.strftime('%m/%d/%Y')
print newformat2
07/16/2014

In [5]:
#Here is a link to the python strftime character references
#http://strftime.org/