Time

15 views
Skip to first unread message

annet

unread,
Jun 17, 2009, 1:01:44 PM6/17/09
to web2py Web Framework
In a table I have a field in which the user enters a time in the
following format: 19:30

In one of my views I want to display records with a time >= the
current time. What is the correct syntax to code this?

timetable=db(db.timetable.from_time>=request.now.?????.select
(db.timetable.ALL)


Kind regards,

Annet.

mdipierro

unread,
Jun 17, 2009, 1:22:30 PM6/17/09
to web2py Web Framework
This should work:

timetable=db(db.timetable.from_time>=request.now).select
(db.timetable.ALL)

Did you try it? Let us know.

massimo

annet

unread,
Jun 17, 2009, 1:36:18 PM6/17/09
to web2py Web Framework
Massimo,

I tried request.now and it works. Thanks.


Annet.

weheh

unread,
Jun 17, 2009, 10:05:22 PM6/17/09
to web2py Web Framework
Massimo, how does request.now know about time zones? (What if server
is in East Kazakhstan and the user is in Hackensack, New Jersey? What
time zone is request.now?)

mdipierro

unread,
Jun 18, 2009, 1:31:20 AM6/18/09
to web2py Web Framework
no it does not where the client is.

cjparsons

unread,
Jun 18, 2009, 3:08:25 AM6/18/09
to web2py Web Framework
> What if server
> is in East Kazakhstan and the user is in Hackensack, New Jersey? What
> time zone is request.now?)

If the server and user are in different time zones I don't believe
there's an easy solution, especially when you consider daylight saving
time (i.e. just converting everything to UTC probably isn't enough).

I'm using fixed_datetime.py in my modules directory.
http://blog.twinapex.fi/2008/06/30/relativity-of-time-shortcomings-in-python-datetime-and-workaround/
which I has a processing overhead that may not be acceptable to you.

In my situation all times are entered and presented in the same time
zone, so I've put
set_default_timezone("Europe/London")
near the bottom of fixed_datetime.py.

Then in my model I call now = datetime.now() and that returns the
current time in London even though the server is in the USA. I use
this 'now' to see if times are in the future etc. I store all the
times in my database as if they're London times.

It would probably be cleaner to use datetime.utcnow() as 'now', store
times as UTC, store user's time zone and convert times before they are
presented to the user.

Chris
Reply all
Reply to author
Forward
0 new messages