4

How do I convert date and time into fraction of days format ?

To be clearer, I have date and time like "26 days,0:16:53". Is there any way to convert this into one number that would be the equivalent value of the above in the format of days only ( fraction value). Example 26.XXXX where 'XXXX' is the fraction of a day corresponding to "0:16:53" in the above example. Is there any way to do this ?

Any help is appreciated.

Thanks in advance

4

1 回答 1

13

Well, it should be something like this:

dt = timedelta(days=26, hours=0, minutes=16, seconds=53)
secs_per_day = 24*60*60    # hours * mins * secs
dt.total_seconds()/secs_per_day
>>>26.011724537037036

Hope this helps!

于 2013-11-06T13:37:23.587 回答