Converts from timedelta into minutes

Question:

I’m calculating with the variables current time and end_program to get the remaining minutes.

current_time = datetime.timedelta(hours = get_24_hours, minutes = get_24_minutes)
end_program = datetime.timedelta(hours = int(program_hours), minutes = int(program_minutes))
current_program = end_program - current_time

Output:

1:30:00
2:00:00
0:45:00
0:45:00
0:15:00
0:15:00
0:35:00

I want to converts the timedelta into minutes:

90
120
45
45
15
15
35

As you can see the timedelta 0:15:00 which it means for 15 minutes so I want to convert it to 15, for 0:35:00 as 35 minutes I want to convert it to 35, for 0:45:00 as 45 minutes I want to convert it to 45, but for 2:00:00 as 2 hours I want to convert it to 120 as 120 minutes. For 1:30:00 as 1 hour and 30 minutes I want to convert it to 90 minutes.

How I can converts from timedelta into minutes?

Asked By: user5874163

||

Answers:

You can convert the seconds into minutes:

print int(current_program.total_seconds() / 60)
Answered By: CookieOfFortune

Look:

>>> import datetime
>>> current_time = datetime.timedelta(hours=24, minutes=24)
>>> end_program = datetime.timedelta(hours = 30, minutes=26)
>>> current_program = end_program - current_time
>>> minutes = current_program.total_seconds()/60.0
>>> minutes
362.0

And look:
https://docs.python.org/2/library/datetime.html#datetime.timedelta

This is a way work for me

My timestamp data is from https://opendata.edp.com/pages/homepage/wind-farm-1-signals-2016.csv

I load the excel data as df

input: df.Timestamp[1]
output: '2016-04-19T12:20:00+00:00'
input: df.Timestamp[2]
output: '2016-01-08T23:10:00+00:00'

First, convert df.Timestamp[1]-df.Timestamp[2] into the Timedalta format as follows

input: Timestamp_in_min = pd.Timestamp(df.Timestamp[1])-pd.Timestamp(df.Timestamp[0])
output: Timedelta('101 days 13:10:00')

Then convert the Timedelta format into the float format in second as follows:

input: Timestamp_in_min.total_seconds()
output: 8773800.0

Then we can convert the time difference into mins by dividing 60.

Answered By: YAN BINGXIN

(df.finish_time- df.start_time).dt.seconds/60

Answered By: Berhan Ay

This is how I approach this:

current_program.view(int)/(10**9 * 60)
Answered By: MathPass
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.