تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
1879 أدوات العرض

I am using V14 and am trying to calculate the duration.   I am using the following formula but it keeps returning a value of 0


for record in self:

    dateDueString = str(record.x_studio_pickup)

    dateMonthString = str(record.x_studio_invoice_date)

    try:

      dateDue = datetime.datetime.strptime( dateDueString, '%Y-%m-%d' )

      dateMonth = datetime.datetime.strptime( dateDueString, '%Y-%m-%d' )

      timeDifference = dateMonth-dateDue

      record['x_studio_duration'] = timeDifference.days

    except:

      record['x_studio_duration']=100000



Can someone tell me the error in my formula? 

الصورة الرمزية
إهمال
أفضل إجابة

Hello Doug,

You are using the same "dateDueString" variable in both "dateDue" and "dateMonth". So you are using the same date to compare with which is why you are getting 0 as an output. 

If you change your code to:

      dateDue = datetime.datetime.strptime( dateDueString, '%Y-%m-%d' )

      dateMonth = datetime.datetime.strptime( dateMonthString, '%Y-%m-%d' )

It should work.

I hope this helps,

Thanks, 

الصورة الرمزية
إهمال