Here is an easy way to do this:
SELECT EventDate, (week(EventDate) - week(curdate())) AS WeeksOut FROM Events;
Example:
mysql> select week('2010-11-18') - week ('2010-10-18'); +------------------------------------------+ | week('2010-11-18') - week ('2010-10-18') | +------------------------------------------+ | 4 | +------------------------------------------+ 1 row in set (0.00 sec)
Another option is to calculate the interval in days and divide by 7:
SELECT EventDate, datediff(EventDate,curdate())/7 AS WeeksOut FROM Events;
Example:
mysql> select datediff('2010-11-18' , '2010-10-18') / 7; +-------------------------------------------+ | datediff('2010-11-18' , '2010-10-18') / 7 | +-------------------------------------------+ | 4.4286 | +-------------------------------------------+ 1 row in set (0.00 sec)
Ike walker
source share