Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ISO 8601 format date for PostgreSQL

I have string containing an ISO 8601 formatted date-time value (ex: 2013-05-21T15:00:00+0200) and time zone (ex: Europe/Rome).

What is the best Postgres data type to represent this date format?

like image 752
Safari Avatar asked May 27 '13 18:05

Safari


People also ask

How do I format a date in ISO 8601?

ISO 8601 Formats ISO 8601 represents date and time by starting with the year, followed by the month, the day, the hour, the minutes, seconds and milliseconds. For example, 2020-07-10 15:00:00.000, represents the 10th of July 2020 at 3 p.m. (in local time as there is no time zone offset specified—more on that below).

What date format does PostgreSQL use?

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.

How do I change the date format in PostgreSQL?

Use dd/mm/yyyy for numeric date representations. Use mm/dd/yyyy for numeric date representations. A value for SET DATESTYLE can be one from the first list (output styles), or one from the second list (substyles), or one from each separated by a comma.

How do I convert datetime to ISO 8601?

toISOString() method is used to convert the given date object's contents into a string in ISO format (ISO 8601) i.e, in the form of (YYYY-MM-DDTHH:mm:ss. sssZ or ±YYYYYY-MM-DDTHH:mm:ss. sssZ). The date object is created using date() constructor.


1 Answers

Type "timestamp with time zone" is what you want.

http://www.postgresql.org/docs/current/static/datatype-datetime.html

like image 176
Pavel Stehule Avatar answered Sep 29 '22 09:09

Pavel Stehule