PyTime Object and Application Crashing

Robert Brewer fumanchu at amor.org
Wed Jan 21 01:02:08 EST 2004


Ryan Scott wrote:
> When I run a query against an access database and the default 
> date for 
> my date/time field is 12/30/1899 the application crashes. 
> Changing this 
> to a different date like 03/03/2003 works.
> The output of the query when returned as a list is as follows:

AFAICT all dates on or before that date will crash. You have several
options:

1. Cast the date value to a string in your SQL before retrieving values;
then parse.
2. Store dates as strings altogether avoiding Access date fields.
3. Access the date value as a float, not a PyTime:

# 12/30/1899, the zero-Date for ADO = 693594
zeroHour = datetime.date(1899, 12, 30).toordinal()

if value is None:
    return None
else:
    aDate, aTime = divmod(float(value), 1)
    aDate = datetime.date.fromordinal(int(aDate) + zeroHour)
    hour, min = divmod(86400 * aTime, 3600)
    min, sec = divmod(min, 60)
    aTime = datetime.time(int(hour), int(min), int(sec))
    return datetime.datetime.combine(aDate, aTime)

HTH!

Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list