I\'ve been stuck with this issue for days, which is something like calculating the numbers of weeks that lies between two days, for example:
Select @Days = (
DATEDIFF(@date1, @date2)/7
That returns a fraction which I'm guessing you'll want to round in some way with CEIL()
, ROUND()
or FLOOR()
My test example with two defined dates:
SELECT FLOOR(DATEDIFF(DATE(20090215), DATE(20090101))/7);
you could also try this as it separates weeks and days.
SET @day1=DATE('2015-02-02');
SET @day2=DATE('2015-02-10');
SELECT CONCAT(SUBSTRING_INDEX(ABS(DATEDIFF(@day1,@day2)/7),'.',1),'Weeks ',
SUBSTRING_INDEX(ABS(DATEDIFF(@day1,@day2)),'.',1)-SUBSTRING_INDEX(ABS(DATEDIFF(@day1,@day2))/7,'.',1)*7,'Days'
)AS diff