1

For the mysql NOW() function, whose system time is used for time calculations? The host of the database or the client executing the statement?

1 Answer 1

2

That should be the time of the host (DB Server).

To be sure, login to MySQL from your client and run

SELECT NOW();

and then run the date() command in PHP and compare.

The NOW() and PHP date() would only be the same if you are running MySQL and Apache/NGINX on the same server.

CAPTAIN's LOG : SUPPLEMENTAL

You may also compare the difference between NOW() and SYSDATE() if you care about the datetime being deterministic.

The example in the documentation for [SYSDATE()] show how

mysql> SELECT NOW(), SLEEP(2), NOW();
+---------------------+----------+---------------------+
| NOW()               | SLEEP(2) | NOW()               |
+---------------------+----------+---------------------+
| 2006-04-12 13:47:36 |        0 | 2006-04-12 13:47:36 |
+---------------------+----------+---------------------+

mysql> SELECT SYSDATE(), SLEEP(2), SYSDATE();
+---------------------+----------+---------------------+
| SYSDATE()           | SLEEP(2) | SYSDATE()           |
+---------------------+----------+---------------------+
| 2006-04-12 13:47:44 |        0 | 2006-04-12 13:47:46 |
+---------------------+----------+---------------------+

Sorry, if this is WTMI, but just know that NOW() comes from the DB Server, not the WebServer.

Back in March of 2014, I talked about monkeying around with the server time and its effect on binary logs : Risk of changing clocktime on MySQL server host

1
  • See also, the startup option: --sysdate-is-now
    – Rick James
    Aug 25, 2018 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.