To shift a date forward or backward a week (seven days), use TO_DAYS( ) and FROM_DAYS( ) : FROM_DAYS « Date Time « SQL / MySQL






To shift a date forward or backward a week (seven days), use TO_DAYS( ) and FROM_DAYS( )

    
mysql>
mysql>
mysql>
mysql> SET @d = '2002-01-01';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @d AS date,
    -> FROM_DAYS(TO_DAYS(@d) + 7) AS 'date + 1 week',
    -> FROM_DAYS(TO_DAYS(@d) - 7) AS 'date - 1 week';
+------------+---------------+---------------+
| date       | date + 1 week | date - 1 week |
+------------+---------------+---------------+
| 2002-01-01 | 2002-01-08    | 2001-12-25    |
+------------+---------------+---------------+
1 row in set (0.00 sec)

mysql>

   
    
    
    
  








Related examples in the same category

1.FROM_DAYS( ) converts the corresponding number of days to a date