Pranav
Pranav

Reputation: 21

How do I create a specific date in PostgreSQL?

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?

Upvotes: 0

Views: 305

Answers (1)

Erwin Brandstetter
Erwin Brandstetter

Reputation: 656784

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.

Upvotes: 2

Related Questions