If you use something like to_date('2024',YYYY'), you have only a 1 in 12 chance of getting the result I expected (1st Jan 2024).
Any other month will mess it up - only in January will the result be as I expected, in e.g. August you will get 1st Aug 2024.
The comment by Connor on
https://asktom.oracle.com/ords/asktom.search?tag=to-date-with-no-month states:
I havent seen a documentation reference that explicitly states this rule (but its been this way for as long as I've used oracle).
But it makes sense (to me :-)) to have the rules like this because you'll always get back a valid date.
If you used "current day" not "first of month" then something like:
to_date('2015-feb')
would work on January 25th but fail if you ran it on January 31st.
I don't think I agree with that one...
Note the YYYY-DD example (also given in the post above):
select to_date('2015-11', 'YYYY-DD') from dual; --> 11-sep-2015 - I rest my case :-)
The final MM-DD example returns a result in the current year, which sort of makes sense. Although an exception or using 1970 would be just as (il)logical I suppose.
D_YYYY | D_YYYY_MM | D_YYYY_MM_DD | D_YYYY_DD | D_MM_DD |
2024-03-01 | 2024-01-01 | 2024-01-01 | 2024-03-15 | 2024-01-15 |