Sei sulla pagina 1di 7

How To Calculate Difference Between Dates in Oracle SQL | ORACLETUTS http://oracletuts.net/tutorials/how-to-calculate-difference-between-dates-i...

1 of 7

How To Calculate Difference Between Dates in Oracle SQL

RSS

LinkedIn

Subscribe

Get Linked

Google
Follow Us

(http://feeds.feedburner.com
(http://www.linkedin.com

(https://plus.google.com

/oracletutsnetwork)

/u/0/110990718337941106533)

/in/tabrahamsen)

Facebook

Twitter

Follow Us

Follow Us

Youtube
Follow Us

Posted February 26th, 2012 by T J Abrahamsen (http://oracletuts.net/author/teab/) & filed under Tutorials (http://ora-

(http://www.facebook.com (http://twitter.com

(https://youtube.com

cletuts.net/category/tutorials/).

/oracletuts)

/user/oracletuts)

/oracletuts)

(http://oracletuts.net/assets/date_diff.jpg)If you have worked with SQL for a while you


have most likely had a time where you wanted to show in a query the difference between two dates.
Advertise

It can be for example to calculate how long a person has been hired in your company,
how old a person is today, etc.

Here (http://oracletuts.net
/advertise

In this tutorial we are going to look at some ways to do this in Oracle SQL.

Social Media
Recommend on Google

Follow @YOU (https://twitter.com/oracletuts)

Before we move on
Before we dive into some of the different ways to find the differences between two dates, I just wanted to let you
know that there are many ways to do this. In this tutorial we are going to cover only a few of them.

Subscribe To Our Newsletter


Grab Your Free Newsletter!

Also, there are different ways to look at things What I mean is: What if you have two Oracle dates, and you
wanted to come up with a query that shows the months between them. Would you then show the difference as i.e 2.7
months, or do you want to say that there are two whole months between? Or, do you want to show the number of
months involved?

Get the best of our site delivered


directly to your inbox.
Enter email address
Subscribe To Our Newsletter!

And, do you want to know i.e. just the months between the dates, or do you want to show how many years there
are between the dates too?
This seems pretty elementary, but I would suggest that before you actually start using the different Oracle date functions, you ask yourself exactly what result you would want first. If you do not know up front what your result should
be presented, you might end up with some complications later, since some of the arithmetic can be tricky to tweak afterwards.
Advertise

Anywaylets get on with it.


Here (http://oracletuts.net

The use of TRUNC with dates

/advertise
/?instructions=highlightzone837

Ok, before we look at the first example I also would like to mention: Remember the time part of your date field, if it
has one. Many times an order date in an order table will have a date with a time on it. Depending on what method you
are using to calculate any differences between your two dates, you might end up with the wrong result.
Let me explain.

Recent Comments

The time part of a TRUNC-ed date


1
2
3
4
5
6
7
8
9

SQL> SELECT TO_CHAR(SYSDATE, 'MM/DD/YYYY HH:MI:SS AM') right_now_trunced


2
,TRUNC(SYSDATE) today
3
,TO_CHAR(TRUNC(SYSDATE), 'MM/DD/YYYY HH:MI:SS AM') right_now_trunced
4 FROM
dual
5 /
RIGHT_NOW_TRUNCED
TODAY
RIGHT_NOW_TRUNCED
---------------------- ----------- ---------------------01/31/2012 06:24:57 PM 1/31/2012
01/31/2012 12:00:00 AM

In the example above you see that if we do a TRUNC on a date that has a time part on it, you will only see the date
part of your date field. If you show you show the time part of a date value that you have used TRUNC on, you will get
a time part of 12:00:00 AM. All dates that do not have a time part specified will by Oracle be thought about as midnight (12:00:00 AM) that day.
1 SQL> SELECT TO_DATE('20120125 11:00:00 AM', 'YYYYMMDD HH:MI:SS AM')
2
2
- TO_DATE('20120120 11:00:00 AM', 'YYYYMMDD HH:MI:SS AM') day_diff
3
3 FROM
dual
4
4 /
5
6
DAY_DIFF

ALI
{ I WANT TO SOLVE MY SOME PROBLEMS IN
ORACLE BY EASY STEPS } Oct 10, 10:13 AM
(http://oracletuts.net/tutorials/introduction-to-aggregatefunctions-in-oracle/#comment-113)
TJ Abrahamsen
{ Hey Vinit - I do not know exactly how
to do that from the top of my head, but you might take a
look at... } Sep 28, 10:06 AM (http://oracletuts.net
/tutorials/how-to-get-elapsed-time-in-plsql/#comment-105)
Vinit
{ Hi, Nice article.. but i need one help. My
requirement is as below: I am calling a procedure P1 in a
package and that procedure... } Sep 26, 10:20 AM
(http://oracletuts.net/tutorials/how-to-get-elapsed-time-inplsql/#comment-99)
Bari
{ Good work, Thanks for explaining transpose
query,have been searching for this one for a while. } Sep
11, 3:38 AM (http://oracletuts.net/tutorials/three-ways-to-

26/10/2012 9:49 AM

How To Calculate Difference Between Dates in Oracle SQL | ORACLETUTS http://oracletuts.net/tutorials/how-to-calculate-difference-between-dates-i...

2 of 7

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

---------5
SQL> SELECT TO_DATE('20120125 10:00:00 AM', 'YYYYMMDD HH:MI:SS AM')
2
- TO_DATE('20120120 11:00:00 AM', 'YYYYMMDD HH:MI:SS AM') day_diff
3 FROM
dual
4 /
DAY_DIFF
---------4.95833333
SQL> SELECT TO_DATE('20120125 11:00:00 AM', 'YYYYMMDD HH:MI:SS AM')
2
- TO_DATE('20120120 10:00:00 AM', 'YYYYMMDD HH:MI:SS AM') day_diff
3 FROM
dual
4 /

transpose-rows-into-columns-in-oracle-sql/#comment-94)
TJ Abrahamsen
{ Hey Rashed.
I have gotten this
question several times, and every time I seem to answer
that as far as I know, the only... } Aug 14, 9:39 PM
(http://oracletuts.net/tutorials/three-ways-to-transposerows-into-columns-in-oracle-sql/#comment-90)
(http://oracletuts.net/tutorials/how-to-calculate-differencebetween-dates-in-oracle-sql/?bwprc_paged=2)

DAY_DIFF
---------5.04166666

If you i.e. are doing calculations where the exact number of days has to be totally correct, my suggestion is to always
TRUNC all dates so that your dates will be all looked at as if they were at midnight that day. You will then always receive a result that is a whole number
NOTE: I am going to discuss this in a later post, but be careful when you use the TRUNC function on dates in your
function.
If you i.e. have a WHERE statement similar to this .
1 WHERE TRUNC(o.order_date) BETWEEN SYSDATE - 30 AND SYSDATE
chances are very high that you will get an explain plan of your query showing a full tablescan on your order table..
Just mentioning it.

Date difference examples


Alrighty thenlets look of some different examples of date difference functionality. Please note that I will be using
dates in these samples that do not have a time part set.

Example # 1: How to get the number of days between two dates


The simplest form of showing this is using functionality we have already shown:
1 SQL> SELECT TO_DATE('20120125', 'YYYYMMDD') - TO_DATE('20120120', 'YYYYMMDD') day_diff
2
2 FROM
dual
3
3 /
4
5
DAY_DIFF
6 ---------7
5
Ok, that was a bit too simple..

Example # 2: How to get number of months between two dates


Using the MONTHS_BETWEEN function
1
2
3
4
5
6
7
8

SQL> SELECT MONTHS_BETWEEN(TO_DATE('20120325', 'YYYYMMDD'), TO_DATE('20120101', 'YYYYMMDD'


2
,(TO_DATE('20120325', 'YYYYMMDD') - TO_DATE('20120101', 'YYYYMMDD')) diff_in_days
3 FROM
dual
4 /
NUM_MONTHS DIFF_IN_DAYS
---------- -----------2.77419354
84

In this example we used the built-in Oracle MONTHS_BETWEEN function, which is pretty convenient to have some
times.

Using plain math to get the number of months between two dates
This is not a method I would recommend, but if you want to calculate months between two days, and you are using
Biblical months..being 30 days per monthit would work fine.
1 SQL> SELECT TRUNC((TO_DATE('20120325', 'YYYYMMDD') - TO_DATE('20120101', 'YYYYMMDD')) / 30) num_months
2
2
,(TO_DATE('20120325', 'YYYYMMDD') - TO_DATE('20120101', 'YYYYMMDD')) diff_in_days
3
3 FROM
dual
4
4 /
5
6 NUM_MONTHS DIFF_IN_DAYS
7 ---------- -----------8
2
84

Using the EXTRACT function


In this example we are going to use the EXTRACT function to find the the month number, and then do a subtraction.

1 SQL> SELECT TO_DATE('20120101', 'YYYYMMDD') start_date


2
2
,TO_DATE('20120325', 'YYYYMMDD') end_date
3
3
,(TO_DATE('20120325', 'YYYYMMDD') - TO_DATE('20120101', 'YYYYMMDD')) diff_in_days
4
4
,EXTRACT(MONTH FROM TO_DATE('20120101', 'YYYYMMDD')) start_month
5
5
,EXTRACT(MONTH FROM TO_DATE('20120325', 'YYYYMMDD')) end_month
6
6
,(EXTRACT(MONTH FROM TO_DATE('20120325', 'YYYYMMDD')) - EXTRACT(MONTH FROM

26/10/2012 9:49 AM

How To Calculate Difference Between Dates in Oracle SQL | ORACLETUTS http://oracletuts.net/tutorials/how-to-calculate-difference-between-dates-i...

3 of 7

7
7 FROM
8
8 /
9
10 START_DATE
11 ----------12 1/1/2012

dual

Most Popular
END_DATE
DIFF_IN_DAYS START_MONTH END_MONTH DIFF_IN_MONTHS
----------- ------------ ----------- ---------- -------------3/25/2012
84
1
3
2

But, what if there are different years on our two dates?

(http://oracletuts.net/tutorials/three-ways-totranspose-rows-into-columns-in-oracle-sql/)

Three Ways To Transpose Rows Into


Columns in Oracle SQL (http://oracletuts.net
/tutorials/three-ways-to-transpose-rows-intoExample # 3: How to get the number of years and months between two dates
columns-in-oracle-sql/)
Read More (http://oracletuts.net/tutorials/threeOne way to do this is actually to use the MONTHS_BETWEEN function like this:
ways-to-transpose-rows-into-columnsin-oracle-sql/) | 5 Comments
1 SQL> SELECT TRUNC(MONTHS_BETWEEN(TO_DATE('20120325', 'YYYYMMDD'), TO_DATE('20100101',
2
2
,(TO_DATE('20120325', 'YYYYMMDD') - TO_DATE('20100101', 'YYYYMMDD')) diff_in_days (http://oracletuts.net/tutorials/three-ways-totranspose-rows-into-columns-in-oracle3
3 FROM
dual
4
4 /
sql/#comments) | 2712 Views
5
(http://oracletuts.net/tutorials/three-ways-to6 TRUNC(MONTHS_BETWEEN(TO_DATE(' DIFF_IN_DAYS
7 ------------------------------ -----------transpose-rows-into-columns-in-oracle-sql/)
8
26
814
But, if we want to show the number of years as well, we can do something like this:
(http://oracletuts.net/tutorials/how-to-calculate1 SQL> SELECT (TO_DATE('20120525', 'YYYYMMDD') - TO_DATE('20100101', 'YYYYMMDD')) diff_in_days difference-between-dates-in-oracle-sql/)
2
2
,TRUNC(MONTHS_BETWEEN(TO_DATE('20120525', 'YYYYMMDD'), TO_DATE('20100101',
3
3
,TRUNC(TRUNC(MONTHS_BETWEEN(TO_DATE('20120525', 'YYYYMMDD'), TO_DATE('20100101' How To Calculate Difference Between Dates
in Oracle SQL (http://oracletuts.net/tutorials
4
4
,MOD(TRUNC(MONTHS_BETWEEN(TO_DATE('20120525', 'YYYYMMDD'), TO_DATE('20100101'
/how-to-calculate-difference-between-dates5
5 FROM
dual
in-oracle-sql/)
6
6 /
Read More (http://oracletuts.net/tutorials
7
8 DIFF_IN_DAYS TRUNC(MONTHS_BETWEEN(TO_DATE(' NUM_YEARS NUM_MONTHS
/how-to-calculate-difference-between-dates9 ------------ ------------------------------ ---------- ---------in-oracle-sql/) | 2 Comments
10
875
28
2
4
(http://oracletuts.net/tutorials/how-to-calculateAnother way to do show the number of years and months could be something like this:
difference-between-dates-in-oraclesql/#comments) | 2270 Views
1 SQL> SELECT TO_DATE('20100101', 'YYYYMMDD') start_date
(http://oracletuts.net/tutorials/how-to-calculate2
2
,TO_DATE('20120525', 'YYYYMMDD') end_date
3
3
,(TO_DATE('20120525', 'YYYYMMDD') - TO_DATE('20100101', 'YYYYMMDD')) diff_in_days difference-between-dates-in-oracle-sql/)
4
4
,EXTRACT(YEAR FROM TO_DATE('20100101', 'YYYYMMDD')) start_month
5
5
,EXTRACT(YEAR FROM TO_DATE('20120525', 'YYYYMMDD')) end_month
6
6
,EXTRACT(MONTH FROM TO_DATE('20100101', 'YYYYMMDD')) start_month
7
7
,EXTRACT(MONTH FROM TO_DATE('20120525', 'YYYYMMDD')) end_month
(http://oracletuts.net/tutorials/how-to-use-oracle8
8
,(EXTRACT(YEAR FROM TO_DATE('20120525', 'YYYYMMDD')) - EXTRACT(YEAR FROM TO_DATE(
analytic-functions-in-oracle-sql/)
9
9
,(EXTRACT(MONTH FROM TO_DATE('20120525', 'YYYYMMDD')) - EXTRACT(MONTH FROM
10
10 FROM
dual
How To Use Oracle Analytic Functions in
11
11 /
Oracle SQL (http://oracletuts.net/tutorials
12
/how-to-use-oracle-analytic-functions13 START_DATE END_DATE
DIFF_IN_DAYS START_MONTH END_MONTH START_MONTH END_MONTH DIFF_IN_YEARS
DIFF_IN_
in-oracle-sql/)
14 ----------- ----------- ------------ ----------- ---------- ----------- ---------- ------------Read-------More (http://oracletuts.net/tutorials
15 1/1/2010
5/25/2012
875
2010
2012
1
5
2
/how-to-use-oracle-analytic-functionsin-oracle-sql/) | 7 Comments
Example # 4: How to get number of years and months between two dates using INTERVAL datatypes
(http://oracletuts.net/tutorials/how-to-use-oracleanalytic-functions-in-oracle-sql/#comments) |
The INTERVAL data types were introduced in Oracle 9i. There are two of them, but in this example we are going to
2201 Views (http://oracletuts.net/tutorials
use the one declared as INTERVAL YEAR TO MONTH.
/how-to-use-oracle-analytic-functionsin-oracle-sql/)
An example of usage of this in an Oracle SQL statement can be the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14

SQL> SELECT x.start_date


2
,x.end_date
3
,(x.end_date - x.start_date) diff_in_days
4
,(x.end_date - x.start_date) YEAR TO MONTH diff_in_months
5 FROM
(
6
SELECT TO_DATE('20100101', 'YYYYMMDD') start_date
7
,TO_DATE('20120515', 'YYYYMMDD') end_date
8
FROM
dual
9
) x
10 /
START_DATE END_DATE
DIFF_IN_DAYS DIFF_IN_MONTHS
----------- ----------- ------------ --------------1/1/2010
5/15/2012
865 +02-04

As you can see, the last field shows the result in the format +02-00. I am NOT going to go into the detailed usage of
this data type, but just know that you can set i.e. the precision of the number of digits you would want to uselike if
you only want to show the months, and not yearyou can specify (i.e.) that you want to show the months as three
digits. The default is 2.
If you want to extract the year and month values above, you can i.e. do like this:
1 SQL> SELECT y.start_date
2
2
,y.end_date
3
3
,y.diff_in_days
4
4
,y.diff_in_interval
5
5
,EXTRACT(YEAR FROM diff_in_interval) num_years
6
6
,EXTRACT(MONTH FROM diff_in_interval) num_months
7
7 FROM
(
8
8
SELECT x.start_date
9
9
,x.end_date
10
10
,(x.end_date - x.start_date) diff_in_days
11
11
,(x.end_date - x.start_date) YEAR TO MONTH diff_in_interval
12
12
FROM
(
SELECT TO_DATE('20100101', 'YYYYMMDD') start_date
13
13
14
14
,TO_DATE('20120515', 'YYYYMMDD') end_date
15
15
FROM
dual
16
16
) x
17
17
) y
18
18 /

(http://oracletuts.net/tutorials/how-to-convertunix-timestamp-to-date-format-in-plsql/)
How To Convert Unix Timestamp To Date
Format In PLSQL (http://oracletuts.net
/tutorials/how-to-convert-unix-timestampto-date-format-in-plsql/)
Read More (http://oracletuts.net/tutorials
/how-to-convert-unix-timestamp-to-date-formatin-plsql/) | 2 Comments (http://oracletuts.net
/tutorials/how-to-convert-unix-timestamp-to-dateformat-in-plsql/#comments) | 1838 Views
(http://oracletuts.net/tutorials/how-to-convertunix-timestamp-to-date-format-in-plsql/)

(http://oracletuts.net/articles/oracle-decodeand-case-what-is-the-difference/)
Oracle DECODE and CASE: What is the
difference (http://oracletuts.net/articles
/oracle-decode-and-case-what-isthe-difference/)
Read More (http://oracletuts.net/articles/oracledecode-and-case-what-is-the-difference/) | 1
Comment (http://oracletuts.net/articles/oracledecode-and-case-what-is-the-difference
/#comments) | 1631 Views (http://oracletuts.net
/articles/oracle-decode-and-case-what-isthe-difference/)

Help us keep on bloggin

26/10/2012 9:49 AM

How To Calculate Difference Between Dates in Oracle SQL | ORACLETUTS http://oracletuts.net/tutorials/how-to-calculate-difference-between-dates-i...

4 of 7

19
20 START_DATE END_DATE
DIFF_IN_DAYS DIFF_IN_INTERVAL NUM_YEARS NUM_MONTHS
21 ----------- ----------- ------------ ---------------- ---------- ---------22 1/1/2010
5/15/2012
865 +02-04
2
4

Blogging can be a lot of spare time work. Please help keep this site
going.

I have to admit that I have actually never used the INTERVAL data types, and to be honest there is a logic with this
data type that I am not sure if I totally understandor have thought through yet
If you look at the sample above, the end date is TO_DATE(20120515, YYYYMMDD). What if we change the end
date to i.e. TO_DATE(20120516, YYYYMMDD)one day later?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

SQL> SELECT y.start_date


2
,y.end_date
3
,y.diff_in_days
4
,y.diff_in_interval
5
,EXTRACT(YEAR FROM diff_in_interval) num_years
6
,EXTRACT(MONTH FROM diff_in_interval) num_months
7 FROM
(
SELECT x.start_date
8
9
,x.end_date
10
,(x.end_date - x.start_date) diff_in_days
11
,(x.end_date - x.start_date) YEAR TO MONTH diff_in_interval
12
FROM
(
13
SELECT TO_DATE('20100101', 'YYYYMMDD') start_date
14
,TO_DATE('20120516', 'YYYYMMDD') end_date
15
FROM
dual
16
) x
17
) y
18 /
START_DATE END_DATE
DIFF_IN_DAYS DIFF_IN_INTERVAL
NUM_YEARS NUM_MONTHS
----------- ----------- ------------ ------------------ ---------- ---------1/1/2010
5/16/2012
866 +02-05
2
5

You will then see that it suddenly shows an extra month. I am not sure exactly how the logic is meant to work, but it
looks like there is a difference in the middle of the month. If you have any explanation of this, your contribution is
welcomed.

In conclusion
As you have seen, using Oracle date arithmetic, there are many ways to get your result. In this tutorial I have shown
some of them, and if you have any additions to the examples..: Sharing is good.
I hope you enjoyed this tutorial, and that it helped you in your work.

Tags: date (http://oracletuts.net/tag/date/), function (http://oracletuts.net/tag/function/), sql (http://oracletuts.net


/tag/sql/)

26/10/2012 9:49 AM

How To Calculate Difference Between Dates in Oracle SQL | ORACLETUTS http://oracletuts.net/tutorials/how-to-calculate-difference-between-dates-i...

5 of 7

Latest SQL

Latest PL/SQL

(http://oracletuts.net/tutorials
/introduction-to-aggregate-functions-in-oracle/)

(http://oracletuts.net/tutorials/how-totokenize-or-parse-a-string-in-plsql/)

Introduction To Aggregate
Functions In Oracle
(http://oracletuts.net/tutorials
/introduction-to-aggregatefunctions-in-oracle/)
Read More (http://oracletuts.net
/tutorials/introduction-to-aggregatefunctions-in-oracle/) | 1 Comment
(http://oracletuts.net/tutorials
/introduction-to-aggregate-functionsin-oracle/#comments) | 479 Views
(http://oracletuts.net/tutorials
/introduction-to-aggregate-functionsin-oracle/)

How To Tokenize Or Parse A String


In PLSQL (http://oracletuts.net
/tutorials/how-to-tokenize-or-parsea-string-in-plsql/)
Read More (http://oracletuts.net
/tutorials/how-to-tokenize-or-parsea-string-in-plsql/) | No Comments
(http://oracletuts.net/tutorials/how-totokenize-or-parse-a-string-in-plsql
/#comments) | 1178 Views
(http://oracletuts.net/tutorials/how-totokenize-or-parse-a-string-in-plsql/)

(http://oracletuts.net/tutorials/quicktip-slicing-a-long-plsql-string-into-smaller-pieces/)
(http://oracletuts.net/tutorials/how-towork-with-downline-hierarchies-in-oracle/)
How To Work With Downline
Hierarchies In Oracle
(http://oracletuts.net/tutorials
/how-to-work-with-downlinehierarchies-in-oracle/)
Read More (http://oracletuts.net
/tutorials/how-to-work-with-downlinehierarchies-in-oracle/) | No Comments
(http://oracletuts.net/tutorials/how-towork-with-downline-hierarchiesin-oracle/#comments) | 579 Views
(http://oracletuts.net/tutorials/how-towork-with-downline-hierarchiesin-oracle/)

Quick Tip: Slicing A Long PLSQL


String Into Smaller Pieces
(http://oracletuts.net/tutorials/quicktip-slicing-a-long-plsql-stringinto-smaller-pieces/)
Read More (http://oracletuts.net
/tutorials/quick-tip-slicing-a-long-plsqlstring-into-smaller-pieces/) | 1
Comment (http://oracletuts.net/tutorials
/quick-tip-slicing-a-long-plsql-stringinto-smaller-pieces/#comments) | 812
Views (http://oracletuts.net/tutorials
/quick-tip-slicing-a-long-plsql-stringinto-smaller-pieces/)

(http://oracletuts.net/tutorials/how-toget-random-dates-in-oracle-plsql/)
(http://oracletuts.net/tutorials/how-torank-records-in-oracle-sql/)
How To Rank Records in Oracle
SQL (http://oracletuts.net/tutorials
/how-to-rank-records-in-oracle-sql/)
Read More (http://oracletuts.net
/tutorials/how-to-rank-recordsin-oracle-sql/) | 1 Comment
(http://oracletuts.net/tutorials/how-torank-records-in-oracle-sql/#comments)
| 765 Views (http://oracletuts.net
/tutorials/how-to-rank-recordsin-oracle-sql/)

How To Get Random Dates In


Oracle PLSQL (http://oracletuts.net
/tutorials/how-to-get-random-datesin-oracle-plsql/)
Read More (http://oracletuts.net
/tutorials/how-to-get-random-datesin-oracle-plsql/) | 1 Comment
(http://oracletuts.net/tutorials/how-toget-random-dates-in-oracleplsql/#comments) | 1010 Views
(http://oracletuts.net/tutorials/how-toget-random-dates-in-oracle-plsql/)

PREVIOUS

NEXT

(http://oracletuts.net
/tutorials/how-toget-random-datesin-oracle-plsql/)

(http://oracletuts.net
/tutorials/three-ways-totranspose-rows-intocolumns-in-oracle-sql/)

Author
TJ Abrahamsen (http://oracletuts.net
/author/teab/)
TJ has worked in the IT business for 20+ years, whereof the last 14+ years
with Oracle. He has obtained an expertise in Oracle SQL and PL/SQL, and
(http://oracletuts.net/)
has a desire to share some of his love for Oracle development.

22
(http://oracletuts.net
/author/teab/)
article(s) published.
Visit my Website
(http://oracletuts.net/)
Follow me on Twitter

26/10/2012 9:49 AM

How To Calculate Difference Between Dates in Oracle SQL | ORACLETUTS http://oracletuts.net/tutorials/how-to-calculate-difference-between-dates-i...

6 of 7

(http://twitter.com/oracletuts)

Say Something
COMMENT RULES:
It is fine to be critical, but if you you are rude, we will delete your comments. Please do not put your URL in the
comment text unless it is relevant to the post and please use your PERSONAL name, blogger name or initials
and not your business name, as the latter comes off like spam.
Have fun and thanks for adding to the conversation!

2 Responses to How To Calculate Difference Between Dates in Oracle SQL


Singh
February 15th, 2012 (http://oracletuts.net/tutorials/how-to-calculate-difference-between-datesin-oracle-sql/#comment-28)
Oracle support Mathematical Subtract - operator on Data datatype. You may directly put in select clause following statement:
to_char (s.last_upd s.created, 999999D99)
{Links moderated away from comment}

TJ Abrahamsen (http://oracletuts.net)
February 15th, 2012 (http://oracletuts.net/tutorials/how-to-calculate-difference-between-datesin-oracle-sql/#comment-30)
Hello Singh Thank you for your input. This is basically what is used in the three first examples.
~ TJ

Leave a Reply
Your Name
Your Email
Your Website

Your Comment Here...

CAPTCHA CodePlease enter the letters and numbers you see in


the picture above before you post the comment
Submit Comment

XHTML: You can use these tags: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

26/10/2012 9:49 AM

How To Calculate Difference Between Dates in Oracle SQL | ORACLETUTS http://oracletuts.net/tutorials/how-to-calculate-difference-between-dates-i...

7 of 7

About (http://oracletuts.net/about/) Copyright & Disclaimer (http://oracletuts.net/copyright-disclaimer/)


Contact Us (http://oracletuts.net/contact)

All content is copyright 2011 oracletuts.net - owned and operated by Exillum (http://exillum.com), United Stated.
Oracle*Tuts and it's sub-domains are not affiliated or endorsed by the Oracle Corporation. The oracle*tuts Learning Network's site(s) are not officially sponsored, or approved by the Oracle
Corporation.
The products and companies mentioned on this website may be the trademarks of their respective owners.

26/10/2012 9:49 AM

Potrebbero piacerti anche