Link to home
Start Free TrialLog in
Avatar of jknj72
jknj72

asked on

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?
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

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.
Avatar of jknj72
jknj72

ASKER

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
WHERE (DateA -DateB)*24 > 3*(365)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>(DateA -DateB)*24

What is the "* 24" for?  Subtracting dates is days not hours between them.
We don't need 24.
Avatar of jknj72

ASKER

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;
Avatar of jknj72

ASKER

Months_Between  was the function I used so I will give it to Slight
Avatar of jknj72

ASKER

thanks