My date and time is different, i want time calculate in total minutes
example:-
A time is 10/19/2011 1:26:00 PM
B time is 11/11/2011 7:14:00 AM
please suggest.....
As noted (and confirmed), the right approach is to work with parsed date/time objects and compute the elapsed interval. For the Python tag on this thread, a concise, reliable method is: parse each timestamp with the correct format into a datetime, subtract to get a timedelta, and convert the difference to minutes with total_seconds() / 60.
An example using the OP's strings follows.
from datetime import datetime
a = "10/19/2011 1:26:00 PM"
b = "11/11/2011 7:14:00 AM"
fmt = "%m/%d/%Y %I:%M:%S %p"
dt_a = datetime.strptime(a, fmt)
dt_b = datetime.strptime(b, fmt)
delta = dt_b - dt_a
minutes = delta.total_seconds() / 60
print(int(minutes)) # 32748 Notes and caveats: the format string "%m/%d/%Y %I:%M:%S %p" matches the month/day order and AM/PM in the examples; change to "%d/%m/%Y..." if day-first. total_seconds()/60 returns a float—use int() or round() as needed. If timestamps come from different time zones or cross DST boundaries, convert to timezone-aware datetimes first (see Python’s datetime and zoneinfo documentation). For messy or locale-dependent input, a tolerant parser such as dateutil.parser can help.
datetime — Basic date and time types
zoneinfo — IANA time zone support
Jump to Post— darkagn 315If you have 2 DateTime objects, you can subtract them to get a TimeSpan object. This TimeSpan object can be expressed in TotalMinutes.
MSDN documentation links:
DateTime.Subtraction operator
If you have 2 DateTime objects, you can subtract them to get a TimeSpan object. This TimeSpan object can be expressed in TotalMinutes.
MSDN documentation links:
DateTime.Subtraction operator
TimeSpan.TotalMinutes
If you have 2 DateTime objects, you can subtract them to get a TimeSpan object. This TimeSpan object can be expressed in TotalMinutes.
MSDN documentation links:
DateTime.Subtraction operator
TimeSpan.TotalMinutes
thanks for your suggestion. its word
thanks for your suggestion. its working
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.