0

I've got a column of varchar type, it contains dates in the format of 8-Jun-12 and 18-Jun-12

I have an empty column of date type

I'd like to fill up my column with the dates as actual dates. I was hoping to get away with something like:

SET formatted_date=to_date(mydatecol, ('[0-9]{1,2}-[a-zA-Z]{3}-[0-9]{2}'));

But my resulting column is null.

2 Answers 2

1

Use to_date():

update mytable
set formatted_date = to_date(mystring, 'dd-mon-yy')
Sign up to request clarification or add additional context in comments.

1 Comment

oh man I feel so dumb, thanks. 11 mins and I can accept the answer
0

PostgreSQL?

You can just hard-cast it:

WITH 
inp(dts) AS (
          SELECT '8-Jun-12'
UNION ALL SELECT '18-Jun-12'
)
SELECT
  dts
, dts::DATE 
FROM inp;
-- out     dts    |    dts     
-- out -----------+------------
-- out  8-Jun-12  | 2012-06-08
-- out  18-Jun-12 | 2012-06-18

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.