Question

I'm running this SQL code.

select  to_char(to_date('14-05-13','yyyy-mm-dd'),'yyyy') from dual;

I don't know why oracle returns 0014 for me.

Could someone help me?

Was it helpful?

Solution 2

you can replace YYYY to RRRR

select to_char(to_date('14-05-13','rrrr-mm-dd'),'rrrr') from dual;

OTHER TIPS

You are giving it "yyyy-mm-dd" for a date format, but you are giving it a date of "14-05-13". So, you are literally telling it that the date is 5/13/0014.

Try either:

select to_char(to_date('14-05-13','yy-mm-dd'),'yyyy') from dual

or preferably:

select to_char(to_date('2014-05-13','yyyy-mm-dd'),'yyyy') from dual;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top