I have a table contain reference time and a user check-in time. Both data is different in type.
Sample data
dtime
= 2023-06-02 08:23:21work_time
= 08:00-18:00
And my code is…
SELECT substring(dtime,-8,5) AS chkin,
SUBSTRING(work_time, 1, 5) AS wt1,
TIMESTAMPDIFF(MINUTE, substring(dtime,-8,5), SUBSTRING(work_time, 1, 5)) AS min_diff
FROM ta_db
WHERE id = 13181;
As a result…
chkin
= 08:23wt1
= 08:00
Now, I want to know how many minutes different from chkin
and wt
with TIMESTAMPDIFF
.
So I did this…
TIMESTAMPDIFF(MINUTE, substring(dtime,-8,5), SUBSTRING(work_time, 1, 5)) AS min_diff
But it returns NULL
. Please be advised.
2
Answers
my solution is to cast using
time()
Try this: