Hi, in my object I have two date fields: date1:fields.date('date 1'), date2:fields.date('date 2'),
I want to retrieve the difference of that 2 fields I tried this : date2 - date1 but I got this error : TypeError: unsupported operand type(s) for -: 'str' and 'str'
Hi mos, You need to do some python level stuffs with dates for getting exact date difference , i will explain with an example
from datetime import datetime fmt = '%Y-%m-%d' from_date = '2013-09-01' -> Take your date field1 to_date = '2013-09-31' -> Take your date field2 d1 = datetime.strptime(from_date, fmt) d2 = datetime.strptime(to_date, fmt) daysDiff = str((d2-d1).days) -> will gives you 29 days daysDiff = str((d2-d1).days + 1) -> will gives you 30 days
Hope it helps you ........ Thanks
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 9/18/13, 12:25 PM|
|Seen: 8996 times|
|Last updated: 11/15/16, 7:50 AM|