inserting/retriving dates in psycopg

Frank Millman frank at
Thu Jan 5 09:24:12 CET 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,
> >        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 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.


More information about the Python-list mailing list