Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql ignore milliseconds from timestamp when doing a select statement

Tags:

postgresql

I have TableA and it has a field of time_captured | timestamp without time zone | default now() It is being used to record when data was inserted into the table. However, I am trying to do a select and ignore milliseconds. So instead of having

2015-07-11 18:06:33.690498
2015-07-12 13:36:21.274509
2015-07-12 13:36:24.222577
2015-07-12 13:36:26.515593

I would like to have

2015-07-11 18:06:33
2015-07-12 13:36:21
2015-07-12 13:36:24
2015-07-12 13:36:26

Having the microseconds in the table is needed but what I do not need is for the output to show the microseconds. How can I do this ? The closest I have come is by using the following but I am not able to figure out how to pull the full date with the time as shown above.

SELECT EXTRACT(YEAR FROM time_captured  AT TIME ZONE 'UTC') FROM server_perf;   date_part

Thank you :)

like image 827
George Mastrokostas Avatar asked Jul 14 '15 00:07

George Mastrokostas


1 Answers

You can use the date_trunc function to achieve this:

select date_trunc('second', time_captured) from server_perf;

see http://www.postgresql.org/docs/9.1/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC for more on this.

like image 85
Ned Rockson Avatar answered Sep 19 '22 22:09

Ned Rockson