[sqlalchemy] Re: Storing UTC Dates

2008-08-28 Thread Werner F. Bruhin

Heston,

Heston James - Cold Beans wrote:

 Hello Guys,

 This might seem like a bit of a naive question but I’m looking for 
 your advice. Being from the UK we operate on Daylight Savings Time 
 which gives us a one hour offset on times for a few months of the year.

 I currently have a DateTime column which is declared like so:

 created = Column(DateTime, default=func.now())

 modified = Column(DateTime, default=func.now(), onupdate=func.now())

 Which generally works very well, when I create a record it inserts the 
 current locale time into the column, however, it stores the datetime 
 with DST applied too it. As I use the datetime at a later point for 
 posting over web services I really need to store the UTC version of 
 now() in the database, without DST applied to it.

 How can I modify the above column definition to do this? Can I simply 
 use something instead of func.now()? I was given the advise to use 
 func.now() by someone but not really sure what it returns, is it a 
 datetime.datetime object? Or a time tuple?

 Or is there a parameter I can pass to Column() or DateTime() which 
 will ensure it uses the UTC format of the date when creating and 
 modifying records?

IIUC func.now is a database function.

You should be able to use datetime instead i.e.:

created = Column(DateTime, default=datetime.datetime.utcnow)

modified = Column(DateTime, default=datetime.datetime.utcnow, 
onupdate=datetime.datetime.utcnow)


Werner

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



[sqlalchemy] Re: Storing UTC Dates

2008-08-28 Thread Heston James - Cold Beans

Hi Werner,

 IIUC func.now is a database function.

Ah, ok, that makes fair sense.

 You should be able to use datetime instead i.e.:

 created = Column(DateTime, default=datetime.datetime.utcnow)

 modified = Column(DateTime, default=datetime.datetime.utcnow, 
 onupdate=datetime.datetime.utcnow)

Yes, this worked just great Werner, I've used that and it seems to have done
the job! I hoped it would be that simple :-)

Thanks again,

Heston


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