Python 2.3 ODBC Datetime limitations

Tim Golden mail at timgolden.me.uk
Sat Jun 2 14:47:32 EDT 2007


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).
>>
>> When I call strptime to convert the value I got ValueError exception:
>>
>> # Table records
>>    for record in self._records:
>>     columns = []
>>     for i in range(len(self._description)):
>>      if self._description[i][1]=='DATE':
>>       strDate=str(record[i])
>>       try:
>>        #convert the date format to be mm/dd/yyyy:
>>        oDate=time.strptime(strDate) #convert to struct_time object
>>        strfDate=time.strftime("%m/%d/%Y", oDate) 
>>
>> columns.append(strfDate)
>>       except ValueError, msg:
>>        raise "Date converstion error", msg
>>
>> ...
>>        Any other solutions that you've heard?
>>
>> Thanks very much in advance,
>>
> 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

(I think the dbidate values are pytime vals; if not, at
least the principle is the same)

TJG



More information about the Python-list mailing list