Reputation: 585
Lets say I have a string representing a date but without the information for the year. I need to convert this string to a date but I explicitly need to set the year of this date. Here is an example:
select to_date('20.01. 23:59:00', 'DD.MM. HH24:MI:SS') from dual
The year of this date is automatically set to the current year. What do I have to do if I want to set the year for example to 1972?
Upvotes: 0
Views: 2954
Reputation:
Hard-code '1972.'
and concatenate before your string; then add YYYY.
to the format model.
select to_date('1972.' || '20.01. 23:59:00', 'YYYY.DD.MM. HH24:MI:SS') from dual;
If instead you have another column with the year, say yr
, and it is in number format, then write to_char(yr) || '.' || ....
within to_date()
.
Upvotes: 3