MySQL Tutorial/Date Time Functions/NOW — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 09:50, 26 мая 2010
Getting the Current Date and Time
There are three functions that you can use to get the current date and time.
NOW() gets both date and time.
CURDATE() works with only the date.
CURTIME() is for the time.
mysql>
mysql> SELECT NOW();
+---------------------+
| NOW() |
+---------------------+
| 2007-07-21 13:54:27 |
+---------------------+
1 row in set (0.00 sec)
Multiple references to a function such as NOW() within a single query always produce the same result
mysql>
This principle also applies to CURDATE(), CURTIME(), UTC_DATE(), UTC_TIME(), UTC_TIMESTAMP(), and to any of their synonyms.
mysql>
mysql> select now(), now();
+---------------------+---------------------+
| now() | now() |
+---------------------+---------------------+
| 2007-07-22 19:46:01 | 2007-07-22 19:46:01 |
+---------------------+---------------------+
1 row in set (0.00 sec)
mysql>
SELECT NOW(), SLEEP(2), NOW();
mysql>
mysql> SELECT NOW(), SLEEP(2), NOW();
+---------------------+----------+---------------------+
| NOW() | SLEEP(2) | NOW() |
+---------------------+----------+---------------------+
| 2007-07-22 19:46:13 | 0 | 2007-07-22 19:46:13 |
+---------------------+----------+---------------------+
1 row in set (2.02 sec)
mysql>