Python 2.3 ODBC Datetime limitations

John Machin sjmachin at lexicon.net
Sat Jun 2 21:56:36 EDT 2007


On Jun 3, 4:47 am, Tim Golden <m... at timgolden.me.uk> wrote:
> Steve Holden wrote:
> > YuePing Lu wrote:
> >> Hello,
>
> >> Has any of you ever used Python odbc to retrieve data from a relational DB?
>
> >> I encountered a problem where it can't handle datetime _earlier than
> >> _*1969*, and _later than _*2040*. It just returned some garbage strings
> >> when I call str(my_date_object).
>
>
> > Reading the documentation for the time module, you will see:
>
> > The epoch is the point where the time starts. On January 1st of that
> > year, at 0 hours, the ``time since the epoch'' is zero. For Unix, the
> > epoch is 1970. To find out what the epoch is, look at gmtime(0).
>
> > The functions in this module do not handle dates and times before the
> > epoch or far in the future. The cut-off point in the future is
> > determined by the C library; for Unix, it is typically in 2038.
>
> Maybe this is of use?
>
> http://timgolden.me.uk/python/win32_how_do_i/use-a-pytime-value.html

which says (inter alia):
"""
If your datetime value is "sane" (ie is anywhere between 1970 and
2038)
"""

That's an interesting interpretation of "sane". FYI some real-world
databases need to store dates before 1970 e.g. dates of birth of
employees.

The answer to the OP's question is easily determined by googling for
'dbidate' in this newsgroup, and is that (1) a dbidate object doesn't
handle dates before 1970-01-01 or after The End of the Unix World in
2038 (not 1969/2040 as the OP posited). (2) the only solution if
"insane dates" are required is to abandon the [outdated as Steve
hinted] odbc module -- try adodb or mxODBC.





More information about the Python-list mailing list