y2k y2k - 1 month ago 18
Python Question

Convert date Python

I have

MMDDYY
dates, i.e. today is
111609


How do I convert this to
11/16/2009
, in Python?

Answer

I suggest the following:

import datetime
date = datetime.datetime.strptime("111609", "%m%d%y")
print date.strftime("%m/%d/%Y")

This will convert 010199 to 01/01/1999 and 010109 to 01/01/2009.