Truncating timestamps

zerkms picture zerkms · Feb 24, 2011 · Viewed 13.7k times · Source

Let's suppose I have a timestamp variable:

select timestamp '2011-02-24 08:30:42 +06:00' from dual;

Is there any way to "truncate" it to something like

'2011-02-24 08:00:00 +06:00'

(I've cut minutes and seconds, but left the timezone)

The target oracle version is 11g r2

Answer

Shannon Severance picture Shannon Severance · Feb 24, 2011
SQL> select to_timestamp_tz(to_char(timestamp '2011-02-24 08:30:42 +06:00', 'YYYY-MM-DD HH24 TZH:TZM'), 'YYYY-MM-DD HH24 TZH:TZM') from dual;

TO_TIMESTAMP_TZ(TO_CHAR(TIMESTAMP'2011-02-2408:30:42+06:00','YYYY-MM-DDTZH:
---------------------------------------------------------------------------
24.02.2011 8:00:00,000000000 +06:00