0

I need to take yesterdays value like:

18-11-2018 06:00:00
select (systimestamp - 1) as ts_bytes from dual;

where time is fixed.

zero323
  • 322,348
  • 103
  • 959
  • 935
ashish
  • 239
  • 2
  • 6
  • 13
  • Try `Systimestamp - INTERVAL '1' DAY ` – Kaushik Nayak Nov 19 '18 at 11:23
  • Possible duplicate of [How to subtract hours from a date in Oracle so it affects the day also](https://stackoverflow.com/questions/30772434/how-to-subtract-hours-from-a-date-in-oracle-so-it-affects-the-day-also) – zero323 Nov 19 '18 at 12:13

4 Answers4

1

I think you are looking for this:

select TRUNC(systimestamp - 1) + INTERVAL '6' HOUR as ts_bytes 
from dual;

or

TRUNC(systimestamp) - INTERVAL '18' HOUR

or if you prefer DATE values rather than TIMESTAMP

select TRUNC(SYSDATE - 1) + 6/24 as ts_bytes 
from dual;
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
0

If you want then time at midnight (00:00:00) of yesterday then truncate the current timestamp to the start of today and then subtract one day:

SELECT TRUNC(SYSTIMESTAMP) - INTERVAL '1' DAY as ts_bytes
FROM   DUAL;

If you want a specific HH:MM:SS time then add an interval with that time:

SELECT TRUNC(SYSTIMESTAMP) - INTERVAL '1' DAY + INTERVAL '12:34:56' HOUR TO SECOND as ts_bytes
FROM   DUAL;
MT0
  • 143,790
  • 11
  • 59
  • 117
0
Select to_char(trunc(sysdate-1),’dd-mm-yyyy’)||’ 06:00:00’ as tyme from dual;

This is funny but should work.

Pang
  • 9,564
  • 146
  • 81
  • 122
0
SELECT  SYSTIMESTAMP - INTERVAL '1' DAY   AS yesterday
FROM    dual;

try this.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 30 '21 at 10:44