Getting Timezone conversion in template with USE_TZ = False;

2013-08-12 Thread Lee Hinde
I'm displaying a date/time field in template. Data in the database: 2013-05-30 00:00:00 template tag: {{ reg.registration_date }} as displayed in the web page: May 29, 2013, 5 p.m. I didn't have a USE_TZ setting until I tried to figure out what was happening here. The data I'm playing with

Re: Timezone conversion

2008-06-14 Thread Rob Hudson
Check out the source of Brian Rosner's project here: http://code.google.com/p/django-timezones/ -Rob On Jun 13, 1:07 am, Darthmahon <[EMAIL PROTECTED]> wrote: > Hi Guys, > > I want to convert a datetime field for an entry in my database to a > specified timezone. Here is the code I have so far:

Re: Timezone conversion

2008-06-13 Thread Horst Gutmann
Django initializes the time module with the timezone specified in your settings module. So if you use datetime.datetime.now() you get a datetime instance from the specified timezone (but still a naive datetime object). If you build your own datetime instances, I think they will get stored as is

Re: Timezone conversion

2008-06-13 Thread Darthmahon
Hi Horst, Thanks to your earlier post I now have time zones working! :) To be honest I didn't like the sound of using the mysql way, sounded a bit too much like a hack to me. One final question though - when you use the datetime field and insert into the database, is that date UTC or based on

Re: Timezone conversion

2008-06-13 Thread Horst Gutmann
Well, to what user's timezone? SET (IIRC) changes the setting for the whole database connection (at least) so if you have multiple inserts for multiple users while using the same connection, the same setting their applies. Meaning it would affect not only one user put potentially multiple users

Re: Timezone conversion

2008-06-13 Thread Darthmahon
Hi, Just been having a chat with someone at work and was offered an alternative. First of he said I should use a timestamp field instead of a datetime field, and then I can use " SET time_zone " in MySQL and that way all dates will be automatically converted to the users timezone.

Re: Timezone conversion

2008-06-13 Thread Darthmahon
Yea that's the one - so hopefully, once I assign it a timezone with .replace it will recognise it properly :) Excellent, I'll try it tonight. Thanks for all your help Horst :) On Jun 13, 9:27 am, "Horst Gutmann" <[EMAIL PROTECTED]> wrote: > Do you mean something like this? > > ValueError:

Re: Timezone conversion

2008-06-13 Thread Horst Gutmann
Do you mean something like this? ValueError: astimezone() cannot be applied to a naive datetime This just means that the datetime instance you're working with, has no timezone associated with it :-) -- Horst On Fri, Jun 13, 2008 at 10:22 AM, Darthmahon <[EMAIL PROTECTED]> wrote: > Right, so

Re: Timezone conversion

2008-06-13 Thread Darthmahon
Right, so it doesn't automatically assign timezone information to it? I've seen some other examples where people have two/three fields just to store the timezone and date but I'd rather not have to go through all of that. At work at the moment, but will try this when I get home :) Any idea what

Re: Timezone conversion

2008-06-13 Thread Horst Gutmann
>From what I can see in the database, DateTime stores its content in the timezone specified in the settings.py by default. So when you fetch a datetime from the database you have to associated the respective timezone with that datetime instance: tzedate =

Timezone conversion

2008-06-13 Thread Darthmahon
Hi Guys, I want to convert a datetime field for an entry in my database to a specified timezone. Here is the code I have so far: from dateutil.parser import * from dateutil.tz import * from datetime import * event = get_object_or_404(Event, id__exact=eventid) edate = event.date tz =