>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 = edate.replace(tzinfo=gettz(settings.TIMEZONE))
tz = gettz('America/New_York')
edatetz = tzedate.astimezone(tz)

Just a wild guess, though.

-- Horst

On Fri, Jun 13, 2008 at 10: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:
>
> from dateutil.parser import *
> from dateutil.tz import *
> from datetime import *
>
> event = get_object_or_404(Event, id__exact=eventid)
> edate = event.date
> tz = gettz('America/New_York')
> edatetz = edate.astimezone(tz)
>
> Now, when I do this, I get something along the lines of "naive
> datetime" for the edate variable. However, if I change the edate
> variable to the following line of code, it works:
>
> edate = datetime.now(tz=gettz('UTC'))
>
> Any ideas why this is happening? Is it the way I am storing the
> datetime in my MySQL database? I'm using a standard datetime field -
> is it missing something?
>
> Cheers,
> Chris
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to