import datetime
baslangicAni = datetime.datetime.now()
baslangicSaati = datetime.datetime.strftime(baslangicAni, "%X")
bitisAni = datetime.datetime.now()
bitisSaati = datetime.datetime.strftime(bitisAni, "%X")
gecenSure = bitisSaati - baslangicSaati
print(f"Geçen Süre: {gecenSure}")
I want to find the difference between two times in seconds, but I can't find it.
CodePudding user response:
You can use .total_seconds()
of the timedelta object you get, when you substract one datetime from a second one.
import datetime
first_date = datetime.datetime.now()
second_date = datetime.datetime(2022, 1, 1)
difference_in_seconds = (first_date-second_date).total_seconds()