Question: How can I display the difference
between two dates?
I want to display the difference between dates, formatted to show
the difference in years, months and days.
Answer: One simple way to display the
difference between dates is to convert an elapsed time into rounded
elapsed minutes.
In this example of displaying date differences, we have a Oracle
logoff trigger that computes the elapsed session time and places it
inside a table:
update
perfstat.stats$user_log set
elapsed_minutes =
round(to_number(logoff_time-logon_time)*1440)
where
user = user_id
and
elapsed_minutes is NULL;
Here is the Oracle SQL query to get the list of dates for the day
between the 2 dates, and the difference between the dates.
SQL> SELECT
2 SYSDATE
Today,
3 SYSDATE - 1 Yesterday,
4 SYSDATE + 1 Tomorrow
5
FROM
6 dual;
TODAY YESTERDAY
TOMORROW
--------- --------- ---------
05-SEP-11 04-SEP-11
06-SEP-11
|
|
|
|
Guarantee your Success!
Oracle is the
world's most complex, robust and flexible database, considered
impossible to master without a mentor.
That's why all BC
Oracle trainers are working professionals, experts in Oracle who
share their tips and secrets. |
|
| |
|
Burleson is the American Team

Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright ? 1996 - 2012
All rights reserved.
Oracle ?
is the registered trademark of Oracle Corporation.
|
|