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

Reply via email to