I have a column named thedate that is varchar. An example of a row is:
Feb 29
I want to convert this value to a date because I want to compare it to today. I have tried to_date but I’m getting a strange value:
0001-01-29 BC
I want it to be 2012-02-29. Any idea why it is not working? I thought it would automatically put in the current year for me and for some reason the month is one behind. It is also listing BC which is not needed.
select to_date(thedate, 'YYYY-MM-DD') from market;
If the data in the field is really “Feb 29”, you’re going to have to fill in the year yourself. That’s why it’s giving you 1 BC. Try this or replace ‘2012’ with a function to get the current year.
select to_date(‘2012 ‘||thedate, ‘YYYY MON DD’) from market;