Trung Tran
Trung Tran

Reputation: 13731

Postgresql date inconsistent format

I am building an app using node with a Postgres backend. I have a column for date where the data type is date. The dates in the database are stored in the format YYYY-MM-DD. However, when I do a query in my app, the date returned is in the format YYYY-MM-DD + (time zone information). For example:

2016-01-06T05:00:00.000Z

Does anyone know how I can prevent this?

Thanks in advance!

Upvotes: 0

Views: 117

Answers (1)

tkone
tkone

Reputation: 22728

Use to_char

SELECT to_char(dateColumn, 'YYYY-MM-DD') AS formattedDate FROM ...

Example:

ubuntu=> SELECT to_char(to_timestamp('2016-01-07', 'YYYY-MM-DD'), 'YYYY-MM-DD');
  to_char
------------
 2016-01-07
(1 row)

Upvotes: 1

Related Questions