Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting time to fraction of days in python

Tags:

python

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

like image 474
Anu145 Avatar asked Dec 12 '22 10:12

Anu145


1 Answers

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!

like image 73
Paulo Bu Avatar answered Jan 03 '23 01:01

Paulo Bu