Вопрос

I use a postgresql table and I have to store automatically time and date after each new insertion

CREATE TABLE dns_table
(
  id serial NOT NULL,
  name_name character varying(15) NOT NULL,
  city text,
  query_time timestamp without time zone DEFAULT CURRENT_TIMESTAMP(0) ;,
  CONSTRAINT dns_table_pkey PRIMARY KEY (id)
)

the format of query_time column is : 2014-04-30 11:04:49, I'm wondering if there is a way to have this format : 2014-04-30 11:04 (without second)

thank you a lot :)

Это было полезно?

Решение

Check the function date_trunc():

SELECT date_trunc('minute', NOW());

Edit: to_char() could be the function you're looking for, just check it.

SELECT to_char(NOW(), 'YYYY-MM-DD HH24:MI');
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top