MySQL Tutorial/Date Time Functions/TIMESTAMPADD — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 13:44, 26 мая 2010

SELECT TIMESTAMPADD(DAY,1,"2003-01-02");

mysql>
mysql> SELECT TIMESTAMPADD(DAY,1,"2003-01-02");
+----------------------------------+
| TIMESTAMPADD(DAY,1,"2003-01-02") |
+----------------------------------+
| 2003-01-03                       |
+----------------------------------+
1 row in set (0.00 sec)
mysql>


SELECT TIMESTAMPADD(FRAC_SECOND,1,"2003-01-02");

mysql>
mysql>
mysql> SELECT TIMESTAMPADD(FRAC_SECOND,1,"2003-01-02");
+------------------------------------------+
| TIMESTAMPADD(FRAC_SECOND,1,"2003-01-02") |
+------------------------------------------+
| 2003-01-02 00:00:00.000001               |
+------------------------------------------+
1 row in set (0.00 sec)


SELECT TIMESTAMPADD(HOUR,1,"2003-01-02");

mysql>
mysql> SELECT TIMESTAMPADD(HOUR,1,"2003-01-02");
+-----------------------------------+
| TIMESTAMPADD(HOUR,1,"2003-01-02") |
+-----------------------------------+
| 2003-01-02 01:00:00               |
+-----------------------------------+
1 row in set (0.00 sec)
mysql>


SELECT TIMESTAMPADD(MONTH,1,"2003-01-02");

mysql>
mysql>
mysql> SELECT TIMESTAMPADD(MONTH,1,"2003-01-02");
+------------------------------------+
| TIMESTAMPADD(MONTH,1,"2003-01-02") |
+------------------------------------+
| 2003-02-02                         |
+------------------------------------+
1 row in set (0.00 sec)


SELECT TIMESTAMPADD(QUARTER,1,"2003-01-02");

mysql>
mysql> SELECT TIMESTAMPADD(QUARTER,1,"2003-01-02");
+--------------------------------------+
| TIMESTAMPADD(QUARTER,1,"2003-01-02") |
+--------------------------------------+
| 2003-04-02                           |
+--------------------------------------+
1 row in set (0.00 sec)
mysql>


SELECT TIMESTAMPADD(SECOND,1,"2003-01-02");

mysql>
mysql> SELECT TIMESTAMPADD(SECOND,1,"2003-01-02");
+-------------------------------------+
| TIMESTAMPADD(SECOND,1,"2003-01-02") |
+-------------------------------------+
| 2003-01-02 00:00:01                 |
+-------------------------------------+
1 row in set (0.00 sec)


SELECT TIMESTAMPADD(WEEK,1,"2003-01-02");

mysql>
mysql> SELECT TIMESTAMPADD(WEEK,1,"2003-01-02");
+-----------------------------------+
| TIMESTAMPADD(WEEK,1,"2003-01-02") |
+-----------------------------------+
| 2003-01-09                        |
+-----------------------------------+
1 row in set (0.00 sec)


SELECT TIMESTAMPADD(YEAR,1,"2003-01-02");

mysql>
mysql> SELECT TIMESTAMPADD(YEAR,1,"2003-01-02");
+-----------------------------------+
| TIMESTAMPADD(YEAR,1,"2003-01-02") |
+-----------------------------------+
| 2004-01-02                        |
+-----------------------------------+
1 row in set (0.00 sec)
mysql>


TIMESTAMPADD(unit,interval,datetime_expr) adds the integer expression interval to datetime_expr

The unit for interval is given by the unit argument.

The unit value may be specified with a prefix of SQL_TSI_.

For example, DAY and SQL_TSI_DAY both are legal.

The unit should be one of the following values:

  1. FRAC_SECOND,
  2. SECOND,
  3. MINUTE,
  4. HOUR,
  5. DAY,
  6. WEEK,
  7. MONTH,
  8. QUARTER, or
  9. YEAR.



mysql>
mysql>
mysql> SELECT TIMESTAMPADD(MINUTE,1,"2003-01-02");
+-------------------------------------+
| TIMESTAMPADD(MINUTE,1,"2003-01-02") |
+-------------------------------------+
| 2003-01-02 00:01:00                 |
+-------------------------------------+
1 row in set (0.02 sec)