[TL;DR]
- Do not use
TO_DATE on a DATE data type.
- Your problem may be on data entry rather than on output as you are probably getting 2-digit year inputs when a 4-digit year is expected.
You do not need to convert change_date to a DATE using TO_DATE as it is already a DATE data type. Just use:
select changedate
from TICKETSTATUS;
If you want your date values to have a specific format then use TO_CHAR (not TO_DATE):
SELECT TO_CHAR( changedate, 'dd.mm.yyyy' )
FROM TICKETSTATUS;
but my Output [] is:
30.03.0019
That may be because you have an error elsewhere in your code that is probably inserting dates from a string with a 2-digit year where a 4-digit year is expected:
CREATE TABLE TicketStatus ( changedate DATE );
INSERT INTO TicketStatus ( changedate ) VALUES ( TO_DATE( '30.03.19', 'dd.mm.yyyy' ) );
Then the year will be 0019.
However, if you use the RR format model for years (or, depending on appropriateness, the YY format model):
INSERT INTO TicketStatus ( changedate ) VALUES ( TO_DATE( '30.03.19', 'dd.mm.rr' ) );
Then the year will be 2019.
SELECT TO_CHAR( changedate, 'dd.mm.yyyy' )
FROM TicketStatus
Outputs:
| TO_CHAR(CHANGEDATE,'DD.MM.YYYY') |
| :------------------------------- |
| 30.03.0019 |
| 30.03.2019 |
db<>fiddle here
It could also be because the NLS_DATE_SETTING in your session is set to dd.mm.yy and the implicit conversion made using TO_DATE on a date column is removing the century but then ALL your dates would have the century 00 (rather than just some of the dates).
to_dateon a column which is already a date.