Stephan
Stephan

Reputation: 43053

Postgresql - How to convert one timestamp to another timestamp with its closer hour?

I have the following timestamp value : 2013-10-09 12:15:55.724+02

I would like to have this instead : 2013-10-09 12:00:00.000+02

I have tried the following :

to_char(creation, 'yyyy-mm-dd HH:00:00.000')

How can I format the timezone ? TZ or tz are not good since they return CEST and cest respectively.

Upvotes: 1

Views: 85

Answers (2)

Ben
Ben

Reputation: 693

I think you want the DATE_TRUNC function.

Upvotes: 1

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125444

select date_trunc('hour', '2013-10-09 12:15:55.724+02'::timestamptz);

http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC

Upvotes: 2

Related Questions