Convert timedelta to Minutes in Python (Example)
In this tutorial, you’ll learn how to convert a timedelta object to minutes in the Python programming language.
The tutorial consists of an example illustrating the conversion of timedelta objects into minutes. To be more precise, the article contains the following:
Let’s start right away!
Example Data & Imported Modules
Let’s import the datetime module.
import datetime # Loading datetime module
Now we should construct some data that we can use in the exemplifying code later on:
td = datetime.timedelta(days=71, seconds=34512, microseconds=150475) # timedelta construction print(td) # printing timedelta # 71 days, 9:35:12.150475
Example: Calculate the Equivalent Time in Days
To convert our timedelta object called td to seconds, we will use the total_seconds() function as given below.
total_seconds = td.total_seconds() # converting timedelta to seconds
Then we will divide the result by 60 to change the unit from seconds to minutes.
td_in_minutes = total_seconds / 60 # converting the second count to minutes print(td_in_minutes) # printing result in minutes # 102815.20250791666
Video, Further Resources & Summary
In case you need further information on the examples of this article, I recommend having a look at the following video on my YouTube channel. In the video, I’m explaining the Python programming syntax of this page:
The YouTube video will be added soon.
In addition, you may want to read the related posts on Statistics Globe.
- Dates & Times in Python – datetime Module
- Introduction to timedelta Objects in Python
- Convert String to timedelta in Python
- Convert Integer to timedelta in Python in R
- Convert datetime Object to Seconds, Minutes & Hours in Python
- Convert Seconds, Minutes & Hours to datetime in Python
- Python Programming Overview
To summarize: In this article, you have learned how to express the timedelta object in minutes in the Python programming language. Please let me know in the comments section, in case you have any additional comments and/or questions.
This page was created in collaboration with Ömer Ekiz. Have a look at Ömer’s author page to get further information about his professional background, a list of all his tutorials, as well as an overview on his other tasks on Statistics Globe.