Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timedelta multiply with float in python

Tags:

People also ask

What is the use of Timedelta () function in Python?

timedelta() function. Python timedelta() function is present under datetime library which is generally used for calculating differences in dates and also can be used for date manipulations in Python. It is one of the easiest ways to perform date manipulations.

What is Timedelta format?

A timedelta represents a duration which is the difference between two dates, time, or datetime instances, to the microsecond resolution. The Timedelta class available in Python's datetime module.

How do you convert Timedelta to seconds?

To get the Total seconds in the duration from the Timedelta object, use the timedelta. total_seconds() method.


I have two dates and can calculate timedelta as usual.

But I want to calculate some percent with resulting timedelta:

full_time = (100/percentage) * timdelta 

But it seems that it can only multiplying with interegs.

How can I use float instead of int as multiplier?

Example:

percentage     = 43.27 passed_time    = fromtimestamp(fileinfo.st_mtime) - fromtimestamp(fileinfo.st_ctime) multiplier     = 100 / percentage   # 2.3110700254217702796394730760342 full_time      = multiplier * passed_time # BUG: here comes exception estimated_time = full_time - passed_time 

If is used int(multiplier) — accuracy suffers.