Compute expiry date

47 views
Skip to first unread message

Annet

unread,
Apr 2, 2015, 9:46:30 AM4/2/15
to web...@googlegroups.com
I a table I defined the following field:

Field('expiryDate', type='date', requires=IS_EMPTY_OR(IS_DATE(format='%d-%m-%Y'))

By default the expiryDate is set to request.now, since there's no need to monthly update
the expiry date, I want to calculate it when the user actually updates or cancels his account.

So if expiryDate is set to 28-11-2014 and the user updates his account on 6-04-2015, the
expiryDate is 28-04-2015, and when the user updates his account on 30-04-2015, the
expiryDate is 28-05-2015

I had a look at relativedelta to solve this problem, but I wonder whether there is an easier
way to solve this problem within web2py.


Kind regards,

Annet

Dave S

unread,
Apr 2, 2015, 3:48:01 PM4/2/15
to web...@googlegroups.com

I'd use the standard python datetime.timedelta, to wit:

   stuff   
= db.executesql("SELECT logstuff, logtime FROM logtable WHERE logstuff  LIKE '%" + request.something )
   newstuff = db.executesql("SELECT logstuff, logtime FROM logtable WHERE id ==" + id )
  
if stuff:
        stuffdelta
= newstuff[0][1] - stuff[-1:][0][1]
       
if (stuffdelta < datetime.timedelta(minutes=10)):
            res2
= db.boottable.insert(stufftime=now, time2stuff=stuffdelta.total_seconds)
 





If you need it in the query, I've used something like (but I'm not, now):
results = db.executesql("SELECT * FROM logtable "
                       
"where logtime < date('now','-0 day') ",
                       
"ORDER BY logtime DESC ;")

(that's for sqlite, but other DBs should have something similar)

I'd think your calculations to be along those lines, give or take a few details.

/dps




Reply all
Reply to author
Forward
0 new messages