0

I need to execute a INSERT statement writing a date with a YYYY-MM-DD format.

Would to_date('2021-09-28','YYYY-MM-DD') work?

1
  • date values do not have "a format". So it's completely irrelevant if you use to_date('2021-09-28', 'yyyy-mm-dd') or to_date('28.09.2021', 'dd.mm.yyyy') Commented Oct 5, 2021 at 13:22

1 Answer 1

2

YYYY-MM-DD is the the ISO 8601 standard date format and unambiguous default in Postgres. Just insert your date literally.

The type date is stored as a 4-byte integer quantity internally, which does not preserve any format. You can format any way you like on output with some basic locale settings or settings of your client, or explicitly with to_char().

Input with to_date('2021-09-28','YYYY-MM-DD') works, too. But you don't need to_date() while operating with ISO format.

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

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.