|
Oracle General Oracle database discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
February 4th, 2004, 01:55 AM
|
Registered User
|
|
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to subtract hours from sysdate in oracle
I want a query.
I have a date column in one table. Now I want compare this date with (sysdate - 50 hours). How to write query.
How to subtract required hours from the sysdate
Thank you
Mouli
|
February 4th, 2004, 12:51 PM
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi mcmouli,
You need to compare the date with (sysdate - 50/24) i.e. you need to convert 50 hours into days first. The following execution sequence shows how you can use "decode(sign())" function to compare the dates in the dummy table t.
----------------------------------------------------------------------
SQL> select to_char(dt, 'fmDay, dd Month yyyy hh24:mi:ss') "Date" from t;
Date
-------------------------------------
Thursday, 1 January 2004 15:15:30
Tuesday, 3 February 2004 10:34:45
SQL> select
2 to_char(dt, 'fmDay, dd Month yyyy hh24:mi:ss') "Date" ,
3 to_char(sysdate, 'fmDay, dd Month yyyy hh24:mi:ss') "Sysdate - 50 hours",
4 decode( sign(dt - (sysdate - 50/24)),
5 -1, 'Date is less than sysdate - 50 hours',
6 1, 'Date is greater than sysdate - 50 hours',
7 'Date is equal to sysdate - 50 hours') "Message"
8 from t
9 /
Date Sysdate - 50 hours Message
------------------------------------- ------------------------------------- ---------------------------------------
Thursday, 1 January 2004 15:15:30 Wednesday, 4 February 2004 10:37:39 Date is less than sysdate - 50 hours
Tuesday, 3 February 2004 10:34:45 Wednesday, 4 February 2004 10:37:39 Date is greater than sysdate - 50 hours
SQL>
----------------------------------------------------------------------
Hope that helps.
Cheers,
azizmasih
|
February 4th, 2004, 12:53 PM
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi mcmouli,
Sorry, I goofed up in the query...
SQL> select
2 to_char(dt, 'fmDay, dd Month yyyy hh24:mi:ss') "Date" ,
3 to_char(sysdate, 'fmDay, dd Month yyyy hh24:mi:ss') "Sysdate",
4 to_char(sysdate - 50/24, 'fmDay, dd Month yyyy hh24:mi:ss') "Sysdate - 50 hours",
5 decode( sign(dt - (sysdate - 50/24)),
6 -1, 'Date is less than sysdate - 50 hours',
7 1, 'Date is greater than sysdate - 50 hours',
8 'Date is equal to sysdate - 50 hours') "Message"
9 from t
10 /
Date Sysdate Sysdate - 50 hours Message
------------------------------------- ------------------------------------- ------------------------------------- ---------------------------------------
Thursday, 1 January 2004 15:15:30 Wednesday, 4 February 2004 10:53:32 Monday, 2 February 2004 8:53:32 Date is less than sysdate - 50 hours
Tuesday, 3 February 2004 10:34:45 Wednesday, 4 February 2004 10:53:32 Monday, 2 February 2004 8:53:32 Date is greater than sysdate - 50 hours
SQL>
Cheers,
azizmasih
|
January 6th, 2011, 09:41 AM
|
Registered User
|
|
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how to get no of days
Hi,
Could you help me how to get no of days with current date.
I have a table with one column with dateWithTime.
essume that, my table name is xyz, coulumn name is date1.
I need to substract date1 with sysdate like this (sysdate-date1)
Please help me how to write the query.
|
January 7th, 2011, 06:52 AM
|
|
How to subtract hours from sysdate in oracle
There are no SQL functions that works on the current row and the previous or next row. The functions work across all rows.
What you'll need to do is write a PL/SQL procedure or function or anonymous block, where your select statement is a cursor, and process the rows of the cursor, using extra variables to hold the previous row's data to use for comparing against the current row.
____________________
fun | mobile | free download | world call
|
|
|