Subtracting dates to get hours and minutes
Gronicus at SGA.Ninja
Gronicus at SGA.Ninja
Tue Dec 13 22:43:35 EST 2022
As is, Test A works.
Comment out Test A and uncomment Test B it fails.
In Test B, I move the data into a variable resulting with the report:
"TypeError: an integer is required (got type tuple)
How do I fix this?
#-----------------------------------------------------------------------------
import datetime
#=================================================
# Test A Hard coded Date/Time
Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30)
# =================================================
# Test B Date/Time data as a variable
#Startt = (2022, 12, 13, 5, 3, 30)
#Stopp = (2022, 12, 12, 21, 15, 30)
#Startt = datetime.datetime(Startt)
#Stopp = datetime.datetime(Stopp)
# =================================================
c = Startt - Stopp
minutes = c.total_seconds() / 60
minutes = c.seconds / 60
hours = 0
while (minutes > 59):
minutes = minutes - 60
hours += 1
minutes = round(minutes)
print()
print (" Hours = <" + str(hours) + ">")
print (" Minutes = <" + str(minutes) + ">")
# -----------------------------------------------------------------------------
More information about the Python-list
mailing list