inserting/retriving dates in psycopg
Frank Millman
frank at chagford.com
Thu Jan 5 03:24:12 EST 2006
Michele Simionato wrote:
> Frank Millman:
>
> > import datetime as dt
>
> > def DbToDate(dat):
> > if isinstance(dat,dt.datetime):
> > return dat # already in datetime format
> > if isinstance(dat,dt.date):
> > return dt.datetime.combine(dat,dt.time(0)) # convert to datetime
>
> This is exactly the type checking I would like to avoid :-/
>
> Michele Simionato
psycopg returns a datetime.datetime object from a TIMESTAMP column, and
a datetime.date object from a DATE column. You should not have to do
any type checking unless you are doing something odd, like I am, and
wanting to convert them all into datetime.datetime objects.
Perhaps if you explain what you are trying to do, I may be able to
suggest something.
Frank
More information about the Python-list
mailing list