Weeks between two dates
560516Feb 7 2007 — edited Feb 7 2007-- How to get the number of weeks between two dates using only SQL;
-- Differently of
-- trunc((date_end - date_begin)/7) or
-- ceil((date_end - date_begin)/7)
-- this select returns the number of weeks used by the interval;
-- Example: if the date_begin is saturday and date_end is the next sunday,
-- this select will return 2 weeks;
-- Genereted on Oracle 10;
-- To be evaluated.
SELECT Count(Count(LEVEL - (To_Number(To_Char(date_begin + LEVEL,'d'))-1)))
FROM dual
WHERE date_end >= date_begin
CONNECT BY LEVEL <= date_end - date_begin
GROUP BY LEVEL - (To_Number(To_Char(date_begin + LEVEL,'d'))-1);