Skip to Content
Menu
This question has been flagged
2 Replies
6382 Views

I am trying to get the time difference between a date and today.  I am getting the error that my field is does not match my TimeDateFormat.  Below is the code I am trying to use, can someone tell me what Odoo uses as a Time Date Format?

for record in self:

dateTimeFormat= "%Y-%m-%d"

dateString2 = "x_studio_field_zWYjZ"

dateTime1= datetime.datetime.today()

dateTime2= datetime.datetime.strptime( dateString2, dateTimeFormat)

totaldifference = dateTime2-dateTime1

print (totaldifference)

Avatar
Discard
Best Answer

How can I calculate the age of a person in Odoo

Avatar
Discard
Best Answer
import datetime
date_string = "Wed, 18 Dec 2013 09:30:00 GMT"
date = datetime.datetime.strptime(date_string, "%a, %d %b %Y %H:%M:%S %Z")
end_date_string = "Wed, 18 Dec 2013 10:15:00 GMT"
end_date = datetime.datetime.strptime(end_date_string, "%a, %d %b %Y %H:%M:%S %Z")
print (end_date-date).seconds/60, "Minutes"
# Difference can get through substracting two datetime objects directly,
#if you have input string then substract after converting to datetime object.
#According to your input change format in while using strptime()

Above is an example to get span between two datetime fields.

first change the format of your datetime properly then do the following code.

datetime_object = datetime.strptime('jan 1 2018 1:33PM', '%b %d %Y %I:%M%p')
diff = datetime_object .date() - datetime.datetime.now().date()
print diff.days
# 74



Avatar
Discard