[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# WEEKS between DATES

Posted on 2000-04-06
Medium Priority
7,309 Views
Hi,

I am trying to find out the number of weeks between 2 dates.

The equivalent in SQL SERVER 7 would be
DateDiff(week,Date1,Date2)

Is there such a function in Oracle.

Thanks for helping..
0
Question by:ayoa
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 3

Expert Comment

ID: 2690846
No there isn't, but ironically there is a "MONTHS_BETWEEN".  Is that all you need or do you need a "week difference" function written for you in PL/SQL?

Gio
0

Author Comment

ID: 2692560
Week difference is really what I need..

Thanks
0

LVL 2

Expert Comment

ID: 2692748
-- gives you the day difference

select (trunc( date2, 'DDD')- trunc( date1, 'DDD')) diff, trunc( date2, 'DDD') date2, trunc( date1, 'DDD') date1
from (select sysdate date1, sysdate+4 date2 from dual)
;

-- gives you the week difference

select (trunc( date2, 'DAY')- trunc( date1, 'DAY'))/ 7 diff, trunc( date2, 'DAY') date2, trunc( date1, 'DAY') date1
from (select sysdate date1, sysdate+4 date2 from dual)
0

LVL 2

Expert Comment

ID: 2703432
Hi,

declare
dDate1 date := sysdate;
dDate2 date := sysdate + 21;
begin
dbms_output.put_line( 'The week difference is ' || trunc( ( dDate2 - dDate1 ) / 7 ) );
end;
/

Andrew.
0

Accepted Solution

Softchoice earned 20 total points
ID: 2705433
select trunc((to_date('01-JAN-2000')-to_date('22-DEC-1999'))/7) weeks from dual
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
###### Suggested Courses
Course of the Month13 days, 23 hours left to enroll