Calculating the number of days from given dates givesa null value!

35 views
Skip to first unread message

mostwanted

unread,
Oct 11, 2019, 7:06:18 AM10/11/19
to web2py-users
I am lost for words & a-little infuriated at this point, a formula that has been working & is working in other applications is not working today when applied to another app!!
I am simply trying to get the number of days from the given dates but the formula gives a NONE value! But i have applied it in the same as in other apps, no changes at all!

CODE
from datetime import datetime

db
.define_table('invoice',
               
Field('customer', 'reference Client_Details',writable=False, label=SPAN('Customer', _style="font-weight: bold;")),
               
Field('client_order', label=SPAN("Item", _style="font-weight: bold;"), requires=IS_NOT_EMPTY()),
               
Field('loaning_date', 'date', label=SPAN('Date Loaned', _style="font-weight: bold;"), requires=IS_NOT_EMPTY()),
               
Field('returning_date', 'date', label=SPAN('Date Returned', _style="font-weight: bold;"), requires=IS_NOT_EMPTY()),
               
Field('daysLoaned', 'integer', compute=lambda r: (datetime.strptime(r['returning_date'], '%Y-%m-%d') - datetime.strptime(r['loaning_date'], '%Y-%m-%d')).days))
The highlited field saves a None value which is not what i am trying get!!

Please help!

Mostwanted

Dave S

unread,
Oct 11, 2019, 4:07:13 PM10/11/19
to web2py-users
Since you are working with date fields, just do the time timedelta directly.

I don't know where the None comes from, but why bother with strptime?

/dps

Reply all
Reply to author
Forward
0 new messages