0

Is there universal way to convert a string to date in PostgreSQL if you don’t know the string format in advance?

For example: the string date may be in yyyy-mm-dd or dd-mm-yyyy format or something else.

Thanks!

1
  • "if you don’t know the string format in advance" no. The only way is to test various formats and see which one succeeds. Commented Apr 22, 2020 at 8:06

2 Answers 2

1

Try typecasting the string to timestamp and then date. Something like:

select '2010-01-01 12:00:00'::timestamp::date

Sign up to request clarification or add additional context in comments.

Comments

0

There is no universal parameter to handle any date format. You have the DateStyle parameter and and the date/time interpretation rules.

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.