Convert a UNIX timestamp in a PostgreSQL INSERT statement

From: "Alan T(dot) Miller" <amiller(at)hollywood101(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Convert a UNIX timestamp in a PostgreSQL INSERT statement
Date: 2004-04-04 11:08:50
Message-ID: 049201c41a35$35c30a60$6e0a0a0a@webdev
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Richard Brooksby 2004-04-04 14:14:03 Re: Convert a UNIX timestamp in a PostgreSQL INSERT statement
Previous Message farqua 2004-04-04 05:19:22 Re: Problem with pgaccess