Database Reference
In-Depth Information
The timeperiod will be a value, followed by the type of time period from Table 11.4.For
example, to find out what the date was this time last week, we can use:
DATE_SUB('2002-12-23', INTERVAL 7 DAY )
And we can take time away from a date as follows:
DATE_SUB('2002-12-23', INTERVAL 1 SECOND )
Figure 11.12 shows these two functions running, using the following script:
SELECT
'2002-12-23' AS TodaysDate,
DATE_SUB('2002-12-23', INTERVAL 7 DAY ) AS lastweek,
DATE_SUB('2002-12-23', INTERVAL 1 SECOND ) AS yesterday
SUBDATE
The SUBDATE() function works exactly the same as the DATE_SUB() function just
described. The format is therefore:
SUBDATE( aDate, INTERVAL timeperiod )
Please refer to the DATE_SUB section above for further information.
TO_DAYS
The TO_DAYS() function converts a date into the number of days since year 0. You pass the
function a date as follows:
TO_DAYS(aDate)
So to convert today's date into days we can use:
TO_DAYS('2002-12-23') as ToDays
Figure 11.12
DATE_SUB() subtracts time periods from given dates.
Search WWH ::




Custom Search