#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Cape Town, South Africa
    Posts
    131
    Rep Power
    12

    Exclamation Help with dates in database required.


    Heya fellas,

    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.

    Regards,
    K.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Cape Town, South Africa
    Posts
    131
    Rep Power
    12

    Cool


    Managed to solve this issue.

    Turns out the pyPgSQL extracts DateTime fields from databases as DateTime objects.

    So all I had to do was
    Code:
    from mx.DateTime import *
    and then
    Code:
    data = execute(query) //pseudocode
    myDateObject = data[4] //random position
    ticks = myDateObject.ticks()
    Then I can just get the current time in ticks using
    Code:
    now().ticks()
    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
    Code:
    newDateObject = localtime(ticks)
    and voila...

    Hope this helps other peeps.

    Later,
    K.

IMN logo majestic logo threadwatch logo seochat tools logo