TO_DAYS( ) can convert DATETIME or TIMESTAMP values to days, if you don't mind having it chop off the time par
t:
mysql>
mysql>
mysql> SET @dt = '2002-01-01 12:30:45';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @dt AS datetime,
-> FROM_DAYS(TO_DAYS(@dt) + 7) AS 'datetime + 1 week',
-> FROM_DAYS(TO_DAYS(@dt) - 7) AS 'datetime - 1 week';
+---------------------+-------------------+-------------------+
| datetime | datetime + 1 week | datetime - 1 week |
+---------------------+-------------------+-------------------+
| 2002-01-01 12:30:45 | 2002-01-08 | 2001-12-25 |
+---------------------+-------------------+-------------------+
1 row in set (0.00 sec)
mysql>
mysql>
Related examples in the same category