Solved

WEEKS between DATES

Posted on 2000-04-06
5
5,850 Views
Last Modified: 2008-04-10
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
Comment
Question by:ayoa
5 Comments
 
LVL 3

Expert Comment

by:jaramill
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

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

Thanks
0
 
LVL 2

Expert Comment

by:Hauke
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

by:AndrewRodionov
ID: 2703432
Hi,

How about this simple example:

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

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now