Monday, November 14, 2016

Convert Oracle date to int using native Microsoft date

SQL Server/Excel

select getdate() 'Today',convert(int,getdate())

2016-11-14 16:05:35.207 42687

Oracle

select current_date,cast(current_date - date '1900-01-01' as int)
from dual;

14-NOV-16 42687

Thursday, November 10, 2016

Oracle subtract days/Hours from current timestamp


select to_timestamp(to_char(systimestamp + INTERVAL '-1' DAY, 'dd-mon-yy hh.mi.ss.ff4 AM')) from dual; ------ -1 day


select to_timestamp(to_char(systimestamp + INTERVAL '-2' HOUR, 'dd-mon-yy hh.mi.ss.ff4 AM')) from dual; ----- -2 hours current date time


select to_timestamp(to_char(systimestamp + INTERVAL '-1' DAY, 'dd-mon-yy hh.mi.ss.ff4 AM')) + INTERVAL '-2' HOUR from dual; ------- -2 hours -1 day