Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1579

Python • Re: subtracting times with datetime

$
0
0
A little late, but MySQL has a command for that:

Code:

create table test (log_time timestamp default current_timestamp());insert into test (log_time) values(default);select log_time,unix_timestamp(log_time) from test limit 1
Then in python

Code:

from time import timestamp=res[0]unix=res[1]now=time()print(int(now-unix)/60)
Which will give you the difference in minutes.
That's assuming that your table column datatype is TIMESTAMP, which it naturally should be.

Statistics: Posted by valkyrie44 — Tue Dec 23, 2025 5:54 pm



Viewing all articles
Browse latest Browse all 1579

Trending Articles