Reputation: 359
I need to truncate the date to the minute so I can be able to group it togheter.
SELECT to_char(SYSDATE,'mm-dd-yyyy hh:mi:ss')as date_min FROM dual
Is there way to do it in Oracle?
Thanks!
Upvotes: 0
Views: 2402
Reputation: 1
To group by time, regardless the day: to_char(sysdate,'HH24:MI')
where you put your date field in place of the 'sysdate'.
My tip is to describe what is your goal. Easier to see what you actually need. (ie. I want to see how the sales are coming in during the day, when do we get the most sales.)
Upvotes: 0
Reputation:
You can use trunc
with a second parameter:
select trunc(SYSDATE, 'mi') as date_min
FROM dual
This way the data type (DATE
) is kept which might be needed for other things
Upvotes: 4
Reputation: 22949
A simple way could be by
SELECT to_char(SYSDATE,'mm-dd-yyyy hh:mi')as date_min from dual
If you want to consider the different elements separately, you can use something like
select extract(month from systimestamp) as month,
extract(day from systimestamp) as day,
extract(year from systimestamp) as year,
extract(hour from systimestamp) as hour,
extract(minute from systimestamp) as minute
from dual
Notice that you need systimestamp
here and not sysdate
, here you find something more
Upvotes: 0