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!

simple date calculations?

gorddanmilojevic-JavaNetNov 2 2015 — edited Nov 3 2015

Hi all,

I have specific requirements based on date calculations,

two date is important, date of begin to work and sysdate with above cases:

date begin of work 5 may 2012 > 05/03/2012 and sysdate

1) case day of sysdate < day begin to work

02/11/2015  -  03/05/2012  =  2 + 30 - 3= 29 for days 10-5=5 for months and 5-2= 3 for years result is 29 days 5 months 3 years

I have select block which work good on 99% cases, but on cases when day begin to work is bigger then sysdate give

with t(id, dt) as (select 1, to_date('05/3/2012','MM/DD/YYYY') from dual)

   select id, dt

        ,floor(months_between(sysdate,dt)/12) as yrs

        ,floor(mod(months_between(sysdate,dt),12)) as months

        ,floor(sysdate-(add_months(dt,floor(months_between(sysdate,dt))))) as dys

  from   t

result

IDDTYRSMONTHSDYS
105/03/20123530

this one day is important, this manual calculation use authorities, so every day is very important.

is there calculations with EXACTLY calculations?

regards

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 1 2015
Added on Nov 2 2015
13 comments
2,709 views