반응형

NOW([fsp])

Returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone.

If the fsp argument is given to specify a fractional seconds precision from 0 to 6, the return value includes a fractional seconds part of that many digits.

mysql> SELECT NOW();
        -> '2007-12-15 23:50:26'
mysql> SELECT NOW() + 0;
        -> 20071215235026.000000

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 for SYSDATE(), which returns the exact time at which it executes.

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 |
+---------------------+----------+---------------------+

In addition, the SET TIMESTAMP statement affects the value returned by NOW() but not by SYSDATE(). This means that timestamp settings in the binary log have no effect on invocations of SYSDATE(). Setting the timestamp to a nonzero value causes each subsequent invocation of NOW() to return that value. Setting the timestamp to zero cancels this effect so that NOW() once again returns the current date and time.

See the description for SYSDATE() for additional information about the differences between the two functions.


(출처: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html)


MySQL 에서 제공하는 document에 보면 위와 같이 나와있다


간단한 예제를 통해 두개의 함수의 차이점을 알수있다.

함수: NOW() -> 함수는 하나의 트랜젝션 or 쿼리 단위로 실행한뒤 동일한 값을 리턴하게 된다.




함수: SYSDATE() -> 함수는 트랜젝션or쿼리 단위에 관계없이 그 함수가 실행되는 시점을 리턴해준다.



간단히!

내가 내린 결론은 sysdate는 말그대로 system시간을 각각 보여주고

NOW는 쿼리문이 실행되고 난뒤 시간을 나타낸다. 


그럼끝.







반응형

+ Recent posts