Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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);
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2007
Added on Feb 7 2007
5 comments
20,077 views