Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > Oracle
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 4th, 2004, 01:55 AM
Registered User
 
Join Date: Feb 2004
Location: KL, , Malaysia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mcmouli
Default 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

Reply With Quote
  #2 (permalink)  
Old February 4th, 2004, 12:51 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Reply With Quote
  #3 (permalink)  
Old February 4th, 2004, 12:53 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #4 (permalink)  
Old January 6th, 2011, 09:41 AM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #5 (permalink)  
Old January 7th, 2011, 06:52 AM
Banned
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtract date stealthdevil Access VBA 2 December 7th, 2007 03:58 PM
Automatically Subtract the Value deepcover1 Access 4 March 14th, 2006 08:33 AM
sysdate mateenmohd SQL Server 2000 3 September 28th, 2003 08:42 AM
Urgent help! Compare a string to Sysdate in Oracle WroteForLuck Classic ASP Basics 1 July 22nd, 2003 02:48 AM
Urgent help needed! Compare a string to Sysdate in WroteForLuck Classic ASP Professional 1 July 17th, 2003 07:11 PM



All times are GMT -4. The time now is 12:44 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.