I'm getting the following error message
ERROR: date/time field value out of range: "13/01/2010" HINT: Perhaps you need a different "datestyle" setting.
I want to get my date in the format DD/MM/YYYY
You can change the format in the postgresql. conf file. The date/time styles can be selected by the user using the SET datestyle command, the DateStyle parameter in the postgresql. conf configuration file, or the PGDATESTYLE environment variable on the server or client.
1) Get the current date To get the current date and time, you use the built-in NOW() function. However, to get the date part only (without the time part), you use the double colons (::) to cast a DATETIME value to a DATE value. The result is in the format: yyyy-mm-dd .
The date format for the date data type in PostgreSQL is yyyy-mm-dd . This is the format used for both storing data and for inserting data.
The TO_DATE function in PostgreSQL is used to converting strings into dates. Its syntax is TO_DATE(text, text) and the return type is date. The TO_TIMESTAMP function converts string data into timestamps with timezone. Its syntax is to_timestamp(text, text) .
SHOW datestyle; DateStyle ----------- ISO, MDY (1 row) INSERT INTO container VALUES ('13/01/2010'); ERROR: date/time field value out of range: "13/01/2010" HINT: Perhaps you need a different "datestyle" setting. SET datestyle = "ISO, DMY"; SET INSERT INTO container VALUES ('13/01/2010'); INSERT 0 1 SET datestyle = default; SET
http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DATESTYLE
DateStyle - Sets the display format for date and time values, as well as the rules for interpreting ambiguous date input values. For historical reasons, this variable contains two independent components: the output format specification (ISO, Postgres, SQL, or German) and the input/output specification for year/month/day ordering (DMY, MDY, or YMD).
Of course it's best to use unambiguous input format (ISO 8601), but there is no problem to adjust it as you need.
You could set the date style to European dd/mm/yyyy
:
SET DateStyle TO European;
I'd advise against this though. I generally try to convert between formats, and keep ISO formatted dates in the data source. After all, it's only a matter of representation, not a matter of different data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With