Date question

I have 2 dates and need to know if the first date is over 3 years different then the 2nd date?

Whats the quickest way to do this?
jknj72Asked:
Who is Participating?
 
slightwv (䄆 Netminder) Commented:
Subtracting two dates in Oracle returns the number of days between them.

There is also a MONTHS_BETWEEN SQL function:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions102.htm#SQLRF00669
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
By year like 12/12/2010  and 12/12/2014   , over 3 years by year, or
By year like 12/12/2010  and 12/13/2013   , over 3 years by day but not by year.
0
 
jknj72Author Commented:
I want to know if a policy is over 3 years old so if I did it by day that would be fine but I just need to know if the difference between DateA and DateB is over 3 years
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Mike EghtebasDatabase and Application DeveloperCommented:
WHERE (DateA -DateB)*24 > 3*(365)

Open in new window

0
 
slightwv (䄆 Netminder) Commented:
>>(DateA -DateB)*24

What is the "* 24" for?  Subtracting dates is days not hours between them.
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
We don't need 24.
0
 
jknj72Author Commented:
I created a function and pass in the 2 dates an d return the months difference...

create or replace FUNCTION Date_Diff(dEffDt IN DATE,dExpDt IN DATE)
   RETURN INT
IS
   v_new_num NUMBER;
BEGIN
   SELECT TRUNC((MONTHS_BETWEEN(dExpDt, dEffDt))) into v_new_num FROM DUAL;
   RETURN v_new_num;
EXCEPTION
WHEN VALUE_ERROR THEN
   RETURN 0;
END Date_Diff;
0
 
jknj72Author Commented:
Months_Between  was the function I used so I will give it to Slight
0
 
jknj72Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.