mysql中日期函数还是比较常用的。主要有NOW()和SYSDATE()两种,虽然都表示当前时间,但使用上有一点点区别。
NOW()取的是语句开始执行的时间,SYSDATE()取的是动态的实时时间。
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_now
NOW()
returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger,NOW()
returns the time at which the function or triggering statement began to execute.) This differs from the behavior forSYSDATE()
, which returns the exact time at which it executes.
如下执行示例
SELECT NOW(),LOCALTIME(),LOCALTIMESTAMP,SYSDATE(),SLEEP(3),NOW(),LOCALTIME(),LOCALTIMESTAMP(),SYSDATE()
