X
X
XWR2021-09-02 20:41:21
Python
XWR, 2021-09-02 20:41:21

How to count how many seconds have passed from a date to another?

I want to count how many seconds have passed since the given date 12:44:11 to 12:45:55 (hour, minute, second)
I want to know how many seconds have passed between them

How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-09-02
@XWR

Don't reinvent the wheel, use datetime.timedelta , that's what it was invented for.

import datetime

moment1 = datetime.datetime(2021, 9, 2, 12, 44, 11)
moment2 = datetime.datetime(2021, 9, 2, 12, 45, 55)
delta = moment2 - moment1
print(delta.total_seconds())

V
Volodymyr Palamar, 2021-09-02
@GORNOSTAY25

https://stackoverflow.com/questions/5522031/conver...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question