Convert a UNIX timestamp in a PostgreSQL INSERT statement

Поиск
Список
Период
Сортировка
От Alan T. Miller
Тема Convert a UNIX timestamp in a PostgreSQL INSERT statement
Дата
Msg-id 049201c41a35$35c30a60$6e0a0a0a@webdev
обсуждение исходный текст
Ответы Re: Convert a UNIX timestamp in a PostgreSQL INSERT statement  (Richard Brooksby <rb@ravenbrook.com>)
Список pgsql-novice
I have a PHP script that captures the time using the PHP time() function. I
want to insert this time into a postgresql table timestamp field. I am at a
loss on how to do this. For example I want to do something like the
following...

<?php

$time_started = time();

INSERT INTO surveys (name, time_started, time_ended) VALUES
('somename',$time_start,$time_ended);
?>

Both the "time_started" and "time_ended" fields are defined as postgresql
timestamps.

The problem is that the "$time_started" variable is seconds since the epoch,
and postgresql wants a timestamp value. Isn't there a simple way to do this
inside the INSERT script without having to resort to application level
scripting???

I have been searching around the net, and looked at the manual but have had
no luck finding a solution.

Thanks in advance,

Alan



В списке pgsql-novice по дате отправления:

Предыдущее
От: joseph speigle
Дата:
Сообщение: Re: create user
Следующее
От: Richard Brooksby
Дата:
Сообщение: Re: Convert a UNIX timestamp in a PostgreSQL INSERT statement