I am having a problem reading a date format in a file I am trying to count the difference between two dates. the format I have is 010108.
I tried to break up the date mmddyy but have run into other errors.
import datetime as dt
# US format month/day/year
#dateStr1 = '7/14/2006'
#dateStr2 = '5/1/2007'
mm1 = 01
dd1 = 01
yy1 = 08
mm2 = 03
dd2 = 12
yy2 = 08
dateStr1 = mm1 + '/' + dd1 + '/' + yy1
dateStr2 = mm2 + '/' + dd2 + '/' + yy2
m1, d1, y1 = (int(x) for x in dateStr1.split('/'))
m2, d2, y2 = (int(x) for x in dateStr2.split('/'))
date1 = dt.date(y1, m1, d1)
date2 = dt.date(y2, m2, d2)
dateDiff = date2 - date1
print 'Difference in days = %d' % dateDiff.days
The file I am reading is a Unix output text file but other files are flopping the date format
any ideas?