Suppose i have a present date and i want to check the date after 90 days than by which method i can do that
Date Time in Python
Collapse
X
-
Tags: None
-
you can use the datetime moduleOriginally posted by parthpatelSuppose i have a present date and i want to check the date after 90 days than by which method i can do that
Code:>>> import datetime >>> nowdate = datetime.date(2007, 1, 1) >>> ninety_days = datetime.timedelta(days=90) >>> after_90 = nowdate + ninety_days >>> after_90 datetime.date(2007, 4, 1) >>> after_90.ctime() 'Sun Apr 1 00:00:00 2007'
-
In the above program parseDate() takes date in a specific format and returns the date after 90 days in the same format..Code:import time def parseDate(date): t = time structT = t.strptime(date,'%Y/%m/%d') objT = t.mktime(structT) return objT if __name__ == '__main__': t = time t1 = parseDate('2007/04/06') t2 = t1 + 90*24*60*60 x = t.localtime(t2) print str(t.strftime('%Y/%m/%d',x))
You can customize it according to ur needs
hope this was helpfulComment
-
the above is shortened like thisOriginally posted by sangeethCode:import time def parseDate(date): t = time... ....
Code:import time as t
Comment
Comment