Loading

SYSDATE() vs NOW() in MySQL

  • SYSDATE() returns the time at which it executes. 返回实际的执行时间。
  • NOW() returns a constant time that indicates the time at which the statement began to execute. 返回这个语句开始执行的时间。
  • The SET TIMESTAMP statement affects the value returned by NOW() but not by SYSDATE().

SET TIMESTAMP 会影响 NOW() 的值但是不会影响 SYSDATE()

SELECT
    SYSDATE(), SLEEP(1) AS '', SYSDATE(),
    NOW(), SLEEP(1) AS '', NOW();

将SYSDATE()作为NOW()的别名

为了防止两者的差异造成的bug,将SYSDATE()作为NOW()的别名 : 使用-sysdate-is-now 关键字参数。

Reference

sysdate-vs-now-in-mysql-whats-the-difference

posted @ 2022-08-22 20:09  wheelchen  阅读(50)  评论(0)    收藏  举报