Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Timestamp: extract full hour

I need to extract the 'full' hour of a timestamp. Like for 2010.03.04 13:13 I want 2010.03.04 13:00 (as a timestamp again).

My current approach is:

TO_TIMESTAMP(TO_CHAR(m.begin, 'yyyy.mm.dd hh24'), 'yyyy.mm.dd hh24')

Is this really the way to go? Who good/bad does it perform (I plan to do a GROUP BY on it).

Thanks for your input!

Cheers, Reto

like image 442
reto Avatar asked Mar 04 '10 10:03

reto


People also ask

Does Datepart work in Oracle?

The function works with a set of two arguments, an input date and the name of the part that has to be extracted from it. However, datepart() function works in SQL Server, Oracle, and Azure SQL databases only.

What is the difference between current timestamp and Systimestamp?

SYSTIMESTAMP returns current timestamp on database server, while current_timestamp returns current timestamp on client machine. So if your database server is in New York and client box is in California, SYSTIMESTAMP will be 3 hours ahead of CURRENT_TIMESTAMP.

What is Systimestamp?

SYSTIMESTAMP returns the system date, including fractional seconds and time zone, of the system on which the database resides. The return type is TIMESTAMP WITH TIME ZONE .


2 Answers

SELECT  TRUNC(m.begin, 'HH24')
FROM    mytable m
like image 79
Quassnoi Avatar answered Oct 16 '22 10:10

Quassnoi


You can use the TRUNC() function:

http://www.psoug.org/reference/date_func.html

like image 34
Álvaro González Avatar answered Oct 16 '22 11:10

Álvaro González