Python ADO Date Time database fields
sjmachin at lexicon.net
Fri Jan 25 10:28:51 CET 2008
On Jan 25, 10:55 am, goldtech <goldt... at worldpost.com> wrote:
> Given an MS-Access table with a date type field with a value of:
> 12:00:00 AM - just"12:00:00 AM", there's nothing else in the field.
> I want to print exactly what's in the field, ie. "12:00:00 AM". What I
> get printed is: 12/30/0/ 00:00:00
> I try:
> print oRS.Fields(dt).Value # print here
val = oRS.Fields(dt).Value
If the last one gives you 0.0, then you have got exactly what's in the
database -- stored as a fraction of a day. Six AM would give you 0.25.
Converting that to 24 hour clock is easy:
>>> val = 0.12345
>>> seconds = int(round(val * 60 * 60 * 24))
>>> minutes, second = divmod(seconds, 60)
>>> hour, minute = divmod(minutes, 60)
>>> '%02d:%02d:%02d' % (hour, minute, second)
>>> ((((46/60.)+57)/60.)+2)/24. # checking
If you don't get 0.0, let us know what you did get.
More information about the Python-list