if request.now and request.utcnow return the same date it means that on your server the local time is UTC-ish. When dealing with timezones you'd better store all dates in your database as UTC, and then either: - use javascript to detect the user timezone and adjust accordingly - let the user choose what is his offset, so you can adjust accordingly
On Tuesday, March 5, 2013 2:04:36 AM UTC+1, jjg0 wrote: > > "That being said, the "today" on the server may not be the same today on > the clients accessing your page from all the timezones in the world...." > > Maybe I wasn't clear in my question, but this is exactly the problem I am > trying to solve. I am trying to provide some kind of function based on > their timezone.. > > So how can I use UTC and timezones to solve this problem? Anytime I have > a table full of stuff with a date field, how do I show a user, "here is > today's stuff" without having to worry about the server showing the user > tomorrow's stuff because of a few hours time difference? I noticed > request.now and request.utcnow by default both return the universal time, > not my local time. What are people doing to solve this problem, surely it > has come up before? > > On Monday, March 4, 2013 2:57:46 PM UTC-5, Niphlod wrote: >> >> no, it's not possible. request.now is always calculated on the server, >> not on the client. That being said, the "today" on the server may not be >> the same today on the clients accessing your page from all the timezones in >> the world.... >> e.g. if you're providing some kind of function based on THEIR timezone >> (i.e. "press this button to delete all your appointments today") you really >> need to start fiddling with UTC and timezone differences. >> >> >> On Monday, March 4, 2013 7:08:23 PM UTC+1, jjg0 wrote: >>> >>> I had asked a question about comparing datetimes here: >>> https://groups.google.com/forum/?fromgroups=#!topic/web2py/2euU80vV2WE >>> The question was answered but I ran into another problem closely >>> related, so I made a sequel. Let's hope we don't have to suffer through a >>> trilogy! >>> >>> Here is what I am doing: >>> >>> I have a model of appointments with a field for the date: >>> >>> . >>> . >>> Field('appointment_date', 'date') >>> . >>> .<other fields> >>> >>> and a controller that should grab all of today's appointments to be >>> printed out: >>> >>> appointment_dates = >>> db(db.appointments.appointment_date==request.now.date()).select() >>> >>> Here is the problem: >>> >>> request.now.date() appears to get the time based on the server. So If >>> the server is say 5 hours ahead, once 7:00pm my time hits I'm going to be >>> looking at tomorrows appointments. (server hits midnight, day cycles but >>> I'm still 7:00pm yesterday) >>> >>> When the controller goes to grab the day's appontments, is it possible >>> to somehow replace request.now.date() with the date of the users pc? >>> Otherwise I'm not really sure how else to go about this problem. >>> >>> Thanks >>> >>> >>> -- --- 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

