January 25th, 2005, 03:27 AM
Help with dates in database required.
In one of my tables in my database I'm storing dates in the format YYYY-MM-DD 00:00:0.0 ie: 2005-01-25 00:00:0.0
I'm accessing this database in Python using pyPgSQL. I need to make use of mxDateTime objects so that I can compare/add/subtract/modify the dates in the database. Thus far, I've been extracting the dates as-is, parsing them, and using the mxDateTime constructors to create instances of mxDateTime objects. Then just the other day, a co-worker tells me that he's pretty sure that I can get mxDateTime objects directly out of my database if I'm using pyPgSQL.
I've been reading through FAQ's and DOC files, and haven't been able to find info on this nifty trick. It would save me a lot of trouble. If anyone knows how to do this please reply. Any suggestions would be appreciated.
January 25th, 2005, 08:31 AM
Managed to solve this issue.
Turns out the pyPgSQL extracts DateTime fields from databases as DateTime objects.
So all I had to do was
from mx.DateTime import *
Then I can just get the current time in ticks using and all I have to do is add/subtract/compare these 2 floating point values to cater for all my needs. Then I can just convert back to a DateTime object using
data = execute(query) //pseudocode
myDateObject = data //random position
ticks = myDateObject.ticks()
newDateObject = localtime(ticks)
Hope this helps other peeps.