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 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 is means by "naive datetime"? > > On Jun 13, 9:16 am, "Horst Gutmann" <[EMAIL PROTECTED]> wrote: >> 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 -~----------~----~----~----~------~----~------~--~---