MySQL Tutorial/Date Time Functions/INTERVAL — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 13:44, 26 мая 2010
Date arithmetic also can be performed using INTERVAL together with the + or - operator:
date + INTERVAL expr unit
date - INTERVAL expr unit
mysql>
mysql> SELECT "1997-12-31 23:59:59" + INTERVAL 1 SECOND;
+-------------------------------------------+
| "1997-12-31 23:59:59" + INTERVAL 1 SECOND |
+-------------------------------------------+
| 1998-01-01 00:00:00 |
+-------------------------------------------+
1 row in set (0.00 sec)
SELECT "1998-01-01" - INTERVAL 1 SECOND;
mysql>
mysql> SELECT "1998-01-01" - INTERVAL 1 SECOND;
+----------------------------------+
| "1998-01-01" - INTERVAL 1 SECOND |
+----------------------------------+
| 1997-12-31 23:59:59 |
+----------------------------------+
1 row in set (0.00 sec)
mysql>
SELECT INTERVAL 1 DAY + "1997-12-31";
mysql>
mysql> SELECT INTERVAL 1 DAY + "1997-12-31";
+-------------------------------+
| INTERVAL 1 DAY + "1997-12-31" |
+-------------------------------+
| 1998-01-01 |
+-------------------------------+
1 row in set (0.00 sec)
mysql>