T0ha / ezodf

ezodf is a Python package to create new or open existing OpenDocument (ODF) files to extract, add, modify or delete document data, forked from dead project https://bitbucket.org/mozman/ezodf
Other
61 stars 23 forks source link

Conversion of midnight datetime string to date instead of datetime #8

Closed btrd closed 2 years ago

btrd commented 9 years ago

I have to read a column of date/time, if I read the date "15/07/2014 23:00:00" there is no problem I get 2014-07-15T23:00:00. But if I read 15/07/2014 00:00:00, I get 2014-07-15 instead of 2014-07-15T00:00:00. I lose the time.

btrd commented 9 years ago

My solution to this problem :

cell = self.data[1, 1].value
try:
    time = datetime.strptime(cell, "%Y-%m-%dT%H:%M:%S")
except ValueError:
    try:
        time = datetime.strptime(cell, "%Y-%m-%d")
    except ValueError:
        #not a date
self.data[x, 0].set_value(time.hour)