date - Make python work with month 13 -
i using following code format date in python 2.7:
month = 13 # right, i'm working 13 month. year = 2012 return datetime.strptime('{}/{}'.format(m, y), '%m/%y').strftime('%m/%y')
now changed python 2.5, , code needs changes because .format doesn't exist in particular version. so, i'm trying this:
return (datetime.strptime(('%d/%d' % (month, year)), '%m/%y') )
and returning:
valueerror: time data did not match format: data=13/2012 fmt=%m/%y
which ok, because i'm using month = '13', need use... possible make work?
thanks!
how this,
month = 13 year = 2012 dt = datetime.datetime(year+month//12, month%12, 1) print(dt) # 2013-01-01 00:00:00
Comments
Post a Comment