I need to calculate the weeks out from a date in my MySQL select statement. There is a date column in one of the tables, and I need to calculate how many weeks away the date is.
SELECT EventDate, (calculation) AS WeeksOut FROM Events;
Example:
- 6 days away, weeks out = 0
- 7 days away, weeks out = 1
- 13 days away, weeks out = 1
- 14 days away, weeks out = 2
Use the DATEDIFF function:
The problem with WEEKS is that it won’t return correct results for dates that cross over January 1st.
The
0is the number of decimal places to use in theROUNDfunction.