1

I've faced a little trouble while i'm working with PHP:$now = date('Y-m-d H:i:s', time());
and MySQL: UPDATE users SET user_lastactivity=NOW()
The problem is, that after i have my data in DB, and when i compare both of them, there is 25 sec difference ... why this happens, when both of them are used for same time (now) and how i can fix this.Thank you guys!

2 Answers 2

2

now will give you the time when this function is being executed. And in you case the are being executed at different time.

If you want to use same time for both statement you can assign $now = NOW();

And use this $now in both places. In query as well as for comparison.

UPDATE users SET user_lastactivity = $now ;

Sign up to request clarification or add additional context in comments.

1 Comment

I've didnt remember to asign NOW() in variable, i will check this out.Thanks!
0

Why don't you use the php var $now in your request to be sure to have the same referential?

UPDATE users SET user_lastactivity = $now

1 Comment

Imho it is much better to always rely on "current database time" and never on "current webserver time"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.