Odd result using Oracle trunc()?

Viewed 117

Why

select trunc(to_date('23/06/2017','DD/MM/YYYY'), 'DAY') from dual;

returns

19.06.17

instead of expected

23.06.17?

We are on Oracle 11.

3 Answers

The DAY format returns the closest starting day of the week. Depending on your DB configuration, this might be a Sunday, Monday (in your case)...

You probably need the DD format instead.

Oracle doc

DAY truncates to closest SUNDAY [1]

you can use DD.

select trunc(to_date('23/06/2017','DD/MM/YYYY'), 'DD') from dual;

Your format is wrong, should be DD format:

select trunc(to_date('23/06/2017','DD/MM/YYYY'), 'DD') from dual;

Date Format Models for the ROUND and TRUNC Date Functions

DDD DD J Day

Related