Home > SQL, Technical > Date differences in PL/SQL (Oracle)

Date differences in PL/SQL (Oracle)

Find the days, months,years difference between two dates in PL/SQL?

Ans:

For days difference:

                        select to_date(‘2010-05-03′,’yyyy-mm-dd’) – to_date(‘2010-05-02′,’yyyy-mm-dd’) from dual;

For months difference:

                 select months_between(to_date(‘2010-05-03′,’yyyy-mm-dd’), to_date(‘2010-07-02′,’yyyy-mm-dd’)) from dual;

For Years difference:

                select months_between(to_date(‘2010-05-03′,’yyyy-mm-dd’), to_date(‘2008-06-03′,’yyyy-mm-dd’))/12 from dual;

Find the day of the date?

Following sql command will give abbriviated day:

           select to_char(sysdate,’dy’) from dual;

For full name of the date

              select to_char(sysdate,’day’) from dual;

Advertisements
Categories: SQL, Technical
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: