웹이야기

MySQL NOW() 본문

D/MySQL

MySQL NOW()

yeon.Biju 2020. 4. 2. 14:31

MySQL 날짜함수, 시간함수

 

NOW()

   - 현재 날짜와 시간을 구하는 함수.

 

NOW([fsp])

의 형태

 

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

 

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

 

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.

 

 

semysql> SELECT NOW();
+---------------------+
| NOW()               |
+---------------------+
| 2020-04-02 14:29:46 |
+---------------------+
1 row in set (0.00 sec)

mysql> SELECT NOW()+0;
+----------------+
| NOW()+0        |
+----------------+
| 20200402142951 |
+----------------+
1 row in set (0.00 sec)

mysql> SELECT NOW(4);
+--------------------------+
| NOW(4)                   |
+--------------------------+
| 2020-04-02 14:30:08.2064 |
+--------------------------+
1 row in set (0.00 sec)

 

 

SELECT NOW(), Smysql> SELECT NOW(), SLEEP(2), NOW();
+---------------------+----------+---------------------+
| NOW()               | SLEEP(2) | NOW()               |
+---------------------+----------+---------------------+
| 2020-04-02 14:30:30 |        0 | 2020-04-02 14:30:30 |
+---------------------+----------+---------------------+
1 row in set (2.00 sec)

 

mysql> SELECT SYSDATE(), SLEEP(2), SYSDATE();
+---------------------+----------+---------------------+
| SYSDATE()           | SLEEP(2) | SYSDATE()           |
+---------------------+----------+---------------------+
| 2020-04-02 14:30:57 |        0 | 2020-04-02 14:30:59 |
+---------------------+----------+---------------------+
1 row in set (2.00 sec)

 

 

'D > MySQL' 카테고리의 다른 글

MySQL PERIOD_DIFF()  (0) 2020.04.02
MySQL PERIOD_ADD()  (0) 2020.04.02
MySQL MONTHNAME()  (0) 2020.04.02
MySQL MONTH()  (0) 2020.04.02
MySQL MINUTE()  (0) 2020.04.02
Comments