MySQL Tutorial/Date Time Functions/TIMESTAMPADD
Содержание
- 1 SELECT TIMESTAMPADD(DAY,1,"2003-01-02");
- 2 SELECT TIMESTAMPADD(FRAC_SECOND,1,"2003-01-02");
- 3 SELECT TIMESTAMPADD(HOUR,1,"2003-01-02");
- 4 SELECT TIMESTAMPADD(MONTH,1,"2003-01-02");
- 5 SELECT TIMESTAMPADD(QUARTER,1,"2003-01-02");
- 6 SELECT TIMESTAMPADD(SECOND,1,"2003-01-02");
- 7 SELECT TIMESTAMPADD(WEEK,1,"2003-01-02");
- 8 SELECT TIMESTAMPADD(YEAR,1,"2003-01-02");
- 9 TIMESTAMPADD(unit,interval,datetime_expr) adds the integer expression interval to datetime_expr
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:
- FRAC_SECOND,
- SECOND,
- MINUTE,
- HOUR,
- DAY,
- WEEK,
- MONTH,
- QUARTER, or
- 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)