Shifting Dates by a Known Amount : DATE_ADD « Date Time « SQL / MySQL






Shifting Dates by a Known Amount

     
mysql>
mysql> SET @d = '2003-08-06';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @d AS 'start date',
    -> DATE_ADD(@d,INTERVAL 7 DAY) AS '1 week',
    -> DATE_ADD(@d,INTERVAL 1 MONTH) AS '1 month',
    -> DATE_ADD(@d,INTERVAL 3 MONTH) AS '3 months',
    -> DATE_ADD(@d,INTERVAL 6 MONTH) AS '6 months';
+------------+------------+------------+------------+------------+
| start date | 1 week     | 1 month    | 3 months   | 6 months   |
+------------+------------+------------+------------+------------+
| 2003-08-06 | 2003-08-13 | 2003-09-06 | 2003-11-06 | 2004-02-06 |
+------------+------------+------------+------------+------------+
1 row in set (0.00 sec)

mysql>

   
    
    
    
    
  








Related examples in the same category

1.what time will it be in 60 hours?
2.For DATETIME- or TIMESTAMP-formatted strings, you can use DATE_ADD( ) to introduce a temporal context:
3.Finding Dates for Weekdays of Other Weeks
4.Finding Dates for Days of the Current Week
5.WHERE DATE_ADD(d,INTERVAL 6 MONTH) >= CURDATE( );
6.Adding a Temporal Interval to a Date
7.Adding 3 days and 4 hours produces this result
8.Perform the week shift first