Convert a UNIX timestamp in a PostgreSQL INSERT statement - Mailing list pgsql-novice

From Alan T. Miller
Subject Convert a UNIX timestamp in a PostgreSQL INSERT statement
Date
Msg-id 049201c41a35$35c30a60$6e0a0a0a@webdev
Whole thread Raw
Responses Re: Convert a UNIX timestamp in a PostgreSQL INSERT statement  (Richard Brooksby <rb@ravenbrook.com>)
List 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 by date:

Previous
From: joseph speigle
Date:
Subject: Re: create user
Next
From: Richard Brooksby
Date:
Subject: Re: Convert a UNIX timestamp in a PostgreSQL INSERT statement