TO_DAYS( ) can convert DATETIME or TIMESTAMP values to days, if you don't mind having it chop off the time par : TO_DAYS « Date Time « SQL / MySQL






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

1.If you pass TO_DAYS( ) a date-and-time value, it extracts the date part and discards the time.
2.Using two date-and-time values that lie a week apart
3.TO_DAYS( ) converts a date to the corresponding number of days
4.Calculating Intervals Between Dates
5.For an interval in weeks, do the same thing and divide the result by seven