PyTime Object and Application Crashing

Robert Brewer fumanchu at amor.org
Wed Jan 21 02:53:09 EST 2004


I wrote:
> 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.
> 
> AFAICT all dates on or before that date will crash. You have 
> several options:
> 
> 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)

Forgot to add, you can then set Date values using floats, as well:

    def datetime_out(self, inValue):
        return self.date_out(inValue) + self.time_out(inValue)
    
    def date_out(self, inValue):
        return inValue.toordinal() - zeroHour
    
    def time_out(self, inValue):
        return float(inValue.second + (inValue.minute * 60) +
                     (inValue.hour * 3600)) / 86400


FuManChu




More information about the Python-list mailing list