On Thursday, April 2, 2015 at 6:46:30 AM UTC-7, Annet wrote:
>
> 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.
>
>
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




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to