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
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.
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.
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 .
SELECT TRUNC(m.begin, 'HH24')
FROM mytable m
You can use the TRUNC() function:
http://www.psoug.org/reference/date_func.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With