Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: how to trunc date column to half an hour
Would this fit your needs?
decode (sign (to_number (to_char (the_date, 'MI')) - 30),
-1, trunc (the_date, 'HH'), trunc (the_date, 'HH') + 1 / 48)
e.g.
SQL> alter session set nls_date_format = 'YYYY/MM/DD HH24:MI:SS' ; Session modifiée.
SQL> with sample_dates as
2 (select to_date ('00:00', 'HH24:MI') as the_date from dual
3 union all select to_date ('00:01', 'HH24:MI') as the_date from dual 4 union all select to_date ('00:15', 'HH24:MI') as the_date from dual 5 union all select to_date ('00:29', 'HH24:MI') as the_date from dual 6 union all select to_date ('00:30', 'HH24:MI') as the_date from dual 7 union all select to_date ('00:31', 'HH24:MI') as the_date from dual 8 union all select to_date ('00:45', 'HH24:MI') as the_date from dual 9 union all select to_date ('00:59', 'HH24:MI') as the_date from dual 10 union all select to_date ('01:00', 'HH24:MI') as the_date from dual 11 union all select to_date ('01:01', 'HH24:MI') as the_date from dual12 )
14 the_date, 15 decode (sign (to_number (to_char (the_date, 'MI')) - 30), 16 -1, trunc (the_date, 'HH'), 17 trunc (the_date, 'HH') + 1 / 48) 18 as rounded_to_half_hour
THE_DATE ROUNDED_TO_HALF_HOU
------------------- -------------------
2007/03/01 00:00:00 2007/03/01 00:00:00 2007/03/01 00:01:00 2007/03/01 00:00:00 2007/03/01 00:15:00 2007/03/01 00:00:00 2007/03/01 00:29:00 2007/03/01 00:00:00 2007/03/01 00:30:00 2007/03/01 00:30:00 2007/03/01 00:31:00 2007/03/01 00:30:00 2007/03/01 00:45:00 2007/03/01 00:30:00 2007/03/01 00:59:00 2007/03/01 00:30:00 2007/03/01 01:00:00 2007/03/01 01:00:00 2007/03/01 01:01:00 2007/03/01 01:00:00
SQL>
De : oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] De la part de Derya Oktay
Envoyé : mardi, 6. mars 2007 10:16
À : oracle-l
Objet : how to trunc date column to half an hour
Hi All,
Is there a way of displaying date columns, truncated to half an hours.
For example: select trunc(sysdate,'HH') from dual;
Regards,
Derya.
FYI. We are usig this sort of functions in group by expressions.
PS. Ghassan thank you for your answer regarding local/global index es in partitions.
--
http://www.freelists.org/webpage/oracle-l
Received on Tue Mar 06 2007 - 14:11:11 CST
![]() |
![]() |