`
import datetime
now = datetime.datetime.now ()
tgl = now.strftime("%Y-%m-%d")
y = now.strftime ('%H:%M:%S')
print(y)
>>> 20:01:10
crsr.execute("SELECT * FROM tblsolar WHERE tanggal LIKE '%s' AND id LIKE '1001' ;" % (tgl))
res = crsr.fetchall()
for i in res:
z = i[9]
print(z)
>>> 8:09:34
can someone help me in this situation
i want to calculate between z and y (time duration)
x = y - z
any help thank you..
i have try
`
import datetime as dt
start_dt = dt.datetime.strptime(x, '%H:%M:%S')
end_dt = dt.datetime.strptime(y, '%H:%M:%S')
diff = (end_dt - start_dt)
print(diff)
strptime() argument 1 must be str, not datetime.timedelta`
3
Answers
ok i got the answer :)
thank @Tim Biegeleisen for correction the code thank NicoDorn for the input
I reckon that the
%s
placeholder should appear alone and outside single quotes:you mean this SQL Syntax?
This should give you the same as the python time with format ‘%H%M%S’