Now() not working as suspected

I use

INSERT INTO user_history (user_id, logged_in) VALUES (1,now());

to record the time I log in. it woks

But when I logout I sun

UPDATE user_history SET logged_out = now() WHERE session_id = 6

But when ck PHPMyAdmin, I see

why are both values being changed?

You should to replace TIMESTAMP type in your login/logout fields with datetime.

1 Like

that was it, now im trying to display the difference between the two times

SELECT logged_in, logged_out, TIMESTAMPDIFF(MINUTE,logged_in,logged_out) AS length FROM user_history WHERE user_id = 1


so the result is 1. how can I break i up to hours, minutes, and seconds?

instead of asking for the difference in minutes, ask for it in seconds, and do the math ™


1 Like

I used the gmdate()

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.