Database Timestamp conversion error

attn.steven.kuo at gmail.com attn.steven.kuo at gmail.com
Fri Apr 6 17:45:28 EDT 2007


On Apr 6, 1:48 pm, kyoso... at gmail.com wrote:

(snipped)

> If I look in the MS Access database, I see the timestamp as "5/6/112".
> Obviously some user didn't enter the correct date and the programmer
> before me didn't give Access strict enough rules to block bad dates.
> How do I test for a malformed date object so I can avoid this? There
> are thousands of records to transfer.
>

time.strptime ?


import time
for date in ("5/6/2008", "5/6/118"):
    try:
        struct_tm = time.strptime(date, "%m/%d/%Y")
        print "Good date: " + date
        print struct_tm
    except ValueError:
        print "Bad date: " + date

--
Hope this helps,
Steven




More information about the Python-list mailing list