snow8261
snow8261

Reputation: 1009

Oracle to_date function usage

When use of to_date function like

select to_date(17,'HH24') from dual 

it return the 2015/3/1 17:00:00 which starts from the first day of the month. I wonder why the to_date function behave like this?

I expect it starts from the current day, so it will show like '2015/3/31 17:00:00'.

How to deal with it?

Upvotes: 0

Views: 158

Answers (2)

Sim1
Sim1

Reputation: 532

From a similar question: Oracle Get only time from To_Date() in a Query? One of the anwsers may explain the behavior:

The reason this doesn't work is because this not a complete date. Even when you use a to_date('07/12/2011','MM/DD/YYYY'), Oracle stores the date and time, but makes all the components of the time ZERO. So the actual date stored is 07/12/2011 HH:MI:SS

So maybe it stores correctly the year and the month but not the day.

Upvotes: 0

Tony Andrews
Tony Andrews

Reputation: 132590

If you are trying to get 17:00 on today's date you can do this:

trunc(sysdate) + 17/24

Upvotes: 1

Related Questions