2

I'm trying to cast a varchar into a date with this following code, and the following error is outputting, any idea why?

ALTER TABLE import.employee
ALTER COLUMN birth_date
TYPE date
USING (birth_date::date);

    ERROR:  date/time field value out of range: "05/29/1960"
HINT:  Perhaps you need a different "datestyle" setting.
********** Error **********

ERROR: date/time field value out of range: "05/29/1960"
SQL state: 22008
Hint: Perhaps you need a different "datestyle" setting.

2 Answers 2

7

Set the datestyle before:

set datestyle = mdy;
Sign up to request clarification or add additional context in comments.

2 Comments

Or using (to_date(birth_date, 'MM/DD/YYYY')) if you don't want to mess around with or worry about connection settings.
Worked like a charm Clodoaldo :)
3

If you need to get the ::date from birth_date, first give the DATE format to your field using the given functions in Data Type Formatting Functions docs.

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.