MySQL Tutorial/Date Time Functions/SYSDATE

Материал из SQL эксперт
Версия от 09:50, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

SELECT SYSDATE(), SLEEP(2), SYSDATE();

mysql>
mysql> SELECT SYSDATE(), SLEEP(2), SYSDATE();
+---------------------+----------+---------------------+
| SYSDATE()           | SLEEP(2) | SYSDATE()           |
+---------------------+----------+---------------------+
| 2007-07-22 19:46:15 |        0 | 2007-07-22 19:46:17 |
+---------------------+----------+---------------------+
1 row in set (2.02 sec)
mysql>


SYSDATE() returns the current date and time.

The format is "YYYY-MM-DD HH:MM:SS" or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context.

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().



mysql>
mysql> SELECT NOW(), SLEEP(2), NOW();
+---------------------+----------+---------------------+
| NOW()               | SLEEP(2) | NOW()               |
+---------------------+----------+---------------------+
| 2007-07-22 19:46:18 |        0 | 2007-07-22 19:46:18 |
+---------------------+----------+---------------------+
1 row in set (2.00 sec)
mysql>
mysql> SELECT SYSDATE(), SLEEP(2), SYSDATE();
+---------------------+----------+---------------------+
| SYSDATE()           | SLEEP(2) | SYSDATE()           |
+---------------------+----------+---------------------+
| 2007-07-22 19:46:20 |        0 | 2007-07-22 19:46:22 |
+---------------------+----------+---------------------+
1 row in set (2.00 sec)
mysql>
mysql>