Convert Datetime Object To Seconds, Minutes & Hours Using pandas Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report We can convert a datetime object to seconds, minutes, and hours using pandas in Python by accessing the attributes of the datetime object and performing the necessary calculations. Convert Datetime Object To Seconds, Minutes & Hours Using pandasConvert a datetime Object to SecondsTo retrieve the seconds from the given string, we use the second attribute . Python3 import pandas as pd # Create a datetime object dt = pd.to_datetime('2024-02-07 12:34:56') # Extract seconds, minutes, and hours seconds = dt.second print("Seconds:", seconds) Output: Seconds: 56Convert datetime Object to MinutesWe can use minute attribute to convert the datetime object to minutes. Python3 import pandas as pd # Create a datetime object dt = pd.to_datetime('2024-02-07 12:34:56') minutes = dt.minute print("Minutes:", minutes) Output: Minutes: 34 Convert datetime Object to HoursWe can use hour attribute to convert the datetime object to hours. Python3 import pandas as pd # Create a datetime object dt = pd.to_datetime('2024-02-07 12:34:56') hours = dt.hour print("Hours:", hours) Output: Hours: 12 Comment More infoAdvertise with us Next Article Convert Datetime Object To Seconds, Minutes & Hours Using pandas H harshajyosimke Follow Improve Article Tags : Data Science Pandas AI-ML-DS Python-pandas Similar Reads Convert A Datetime Object To Seconds We are given a datetime object and our task is to convert it into seconds. This is useful in time-based calculations like measuring duration, intervals, or storing timestamps in a simplified format. For example, converting 01:01:09 to seconds will give 3669.0.Using total_seconds()We create a datetim 2 min read Convert Datetime Object To Local Time Zone In Pandas Pandas has established itself as one of the most powerful and versatile libraries in Python. When working with time series data, handling datetime objects efficiently becomes paramount. Oftentimes, datasets contain timestamps in various time zones, necessitating conversion to a consistent reference 2 min read How to Convert Time Durations to Numeric (Hours, Minutes, and Seconds) in Polars Working with time durations in data analysis can be tricky, especially when these durations are represented in various formats like HH:MM:SS or other string representations. Converting these time durations into numeric values, such as total seconds, minutes, or hours, can simplify calculations and f 3 min read How to Convert Datetime to Date in Pandas ? DateTime is a collection of dates and times in the format of "yyyy-mm-dd HH:MM:SS" where yyyy-mm-dd is referred to as the date and HH:MM:SS is referred to as Time. In this article, we are going to discuss converting DateTime to date in pandas. For that, we will extract the only date from DateTime us 4 min read Working with Datetime Objects and Timezones in Python Python provides tools for managing date and time using the datetime module. Whether you're fetching the current time, formatting it, handling timezones or calculating time differences, this module makes it simple. For example, you can easily convert "2001-11-15 01:20:25" from Asia/Kolkata to America 4 min read Like