If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > sysdate - yesterday's date and time

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-12, 07:42
halstead halstead is offline
Registered User
 
Join Date: Feb 2012
Posts: 2
sysdate - yesterday's date and time

I need to compare a timestamp with yesterday's date at 2am and am having difficulty formulating the sysdate format.
Can you help please
Reply With Quote
  #2 (permalink)  
Old 02-09-12, 08:51
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
I have difficulties in understanding what you need. "Yesterday" was, obviously, "before today" (but that's probably not a comparison you are looking for).

Topic title contains a hyphen (-) sign. Is it a "minus" (i.e. you want to subtract two date values)? If so, here you are:
Code:
SQL> select sysdate                now,
  2    trunc(sysdate - 1) + 2/24   yesterday_2_am,
  3    --
  4    sysdate - (trunc(sysdate - 1) + 2/24) num_of_days  --> difference
  5  from dual;

NOW                 YESTERDAY_2_AM      NUM_OF_DAYS
------------------- ------------------- -----------
09.02.2012 14:50:09 08.02.2012 02:00:00  1,53482639

SQL>
Result is NUMBER OF DAYS between two dates. If you need to recalculate it to another format (days, hours, minutes), do some arithmetic (1 day = 24 hours, 1 hour = 60 minutes, etc.).
Reply With Quote
  #3 (permalink)  
Old 02-09-12, 09:10
halstead halstead is offline
Registered User
 
Join Date: Feb 2012
Posts: 2
thanks for your reply.
That has helped resolve the problem
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
Pingbacks are On
Refbacks are On