from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
date_format = '%Y-%m-%d'
joining_date = '2013-08-23'
current_date = (datetime.today()).strftime(date_format)
d1 = datetime.strptime(joining_date, date_format).date()
d2 = datetime.strptime(current_date, date_format).date()
r = relativedelta(d2,d1)
print r.years
print r.months
print r.days
from dateutil.relativedelta import relativedelta
date_format = '%Y-%m-%d'
joining_date = '2013-08-23'
current_date = (datetime.today()).strftime(date_format)
d1 = datetime.strptime(joining_date, date_format).date()
d2 = datetime.strptime(current_date, date_format).date()
r = relativedelta(d2,d1)
print r.years
print r.months
print r.days
Thanks!!!!!!!!! Enjoy Programming :)
Interesting! I'm looking for something similar but just for minutes. I've created a datetime field that I populate with datetime.datetime.now() trough a server action linked to a button and now I would like to compute the minutes that passed to complete an order using the date_order field as source on pos.order model. Can you tell me how should I edit your syntax? Thanks!
ReplyDeleteTo find the desired results you have to convert both the dates in minutes. Better you check here: http://stackoverflow.com/questions/2788871/python-date-difference-in-minutes
ReplyDeleteCheck "Ken Cochrane's " answer. It will fix your thing.
Yes! Exactly what I need! Thanks!
DeleteThumbs up!! :)
ReplyDelete