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 now was all migrated from another system directly
to the backend, i.e., I didn't migrate through django.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


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:
>
> 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
-~--~~~~--~~--~--~---



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 into the database. So the timezone setting
should only be relevant for now() calls IMO.

-- Horst

On Fri, Jun 13, 2008 at 8:31 PM, Darthmahon <[EMAIL PROTECTED]> wrote:
> 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 my TIME_ZONE setting
> in Django?
>
> On Jun 13, 4:59 pm, "Horst Gutmann" <[EMAIL PROTECTED]> wrote:
>> 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 that you actually don't want to use this
>> timezone.
>>
>> IMO stuff like that should be left to the application esp. if you want
>> users to have different timezones. In such a case you'd have to store
>> the user's timezone somewhere. Here it would probably be best to store
>> the "name" of the timezone (like for instance Europe/Vienna). I'm not
>> 100% sure, but IMO this would give you the benefit of leaving the
>> whole DST stuff to the underlying system instead of having to fight
>> with questions like "Does the user live in a country with n hours of
>> offset where there is DST?", "When does DST apply in this user's
>> timezone?", etc.
>>
>> If I'm not mistaken dateutil.tz.tzfile (which you get when using
>> dateutil.tz.gettz) handles all this.
>>
>> -- Horst
>>
>> On Fri, Jun 13, 2008 at 3:01 PM, Darthmahon <[EMAIL PROTECTED]> wrote:
>> > 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.
>>
>> >http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html
>>
>> > Any ideas if this is a good way of doing this?
>>
>> > On Jun 13, 9:37 am, Darthmahon <[EMAIL PROTECTED]> wrote:
>> >> 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: 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'))
>>

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 my TIME_ZONE setting
in Django?

On Jun 13, 4:59 pm, "Horst Gutmann" <[EMAIL PROTECTED]> wrote:
> 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 that you actually don't want to use this
> timezone.
>
> IMO stuff like that should be left to the application esp. if you want
> users to have different timezones. In such a case you'd have to store
> the user's timezone somewhere. Here it would probably be best to store
> the "name" of the timezone (like for instance Europe/Vienna). I'm not
> 100% sure, but IMO this would give you the benefit of leaving the
> whole DST stuff to the underlying system instead of having to fight
> with questions like "Does the user live in a country with n hours of
> offset where there is DST?", "When does DST apply in this user's
> timezone?", etc.
>
> If I'm not mistaken dateutil.tz.tzfile (which you get when using
> dateutil.tz.gettz) handles all this.
>
> -- Horst
>
> On Fri, Jun 13, 2008 at 3:01 PM, Darthmahon <[EMAIL PROTECTED]> wrote:
> > 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.
>
> >http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html
>
> > Any ideas if this is a good way of doing this?
>
> > On Jun 13, 9:37 am, Darthmahon <[EMAIL PROTECTED]> wrote:
> >> 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: 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 

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 that you actually don't want to use this
timezone.

IMO stuff like that should be left to the application esp. if you want
users to have different timezones. In such a case you'd have to store
the user's timezone somewhere. Here it would probably be best to store
the "name" of the timezone (like for instance Europe/Vienna). I'm not
100% sure, but IMO this would give you the benefit of leaving the
whole DST stuff to the underlying system instead of having to fight
with questions like "Does the user live in a country with n hours of
offset where there is DST?", "When does DST apply in this user's
timezone?", etc.

If I'm not mistaken dateutil.tz.tzfile (which you get when using
dateutil.tz.gettz) handles all this.

-- Horst

On Fri, Jun 13, 2008 at 3:01 PM, Darthmahon <[EMAIL PROTECTED]> wrote:
> 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.
>
> http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html
>
> Any ideas if this is a good way of doing this?
>
> On Jun 13, 9:37 am, Darthmahon <[EMAIL PROTECTED]> wrote:
>> 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: 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
-~--~~~~--~~--~--~---



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.

http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html

Any ideas if this is a good way of doing this?

On Jun 13, 9:37 am, Darthmahon <[EMAIL PROTECTED]> wrote:
> 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: 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
-~--~~~~--~~--~--~---



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: 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
-~--~~~~--~~--~--~---



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 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
-~--~~~~--~~--~--~---



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 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
-~--~~~~--~~--~--~---



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 = 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
-~--~~~~--~~--~--~---



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 = 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
-~--~~~~--~~--~--~---