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

From Richard Brooksby
Subject Re: Convert a UNIX timestamp in a PostgreSQL INSERT statement
Date
Msg-id 53A6CEBC-8642-11D8-97F4-000393D3C042@ravenbrook.com
Whole thread Raw
In response to Convert a UNIX timestamp in a PostgreSQL INSERT statement  ("Alan T. Miller" <amiller@hollywood101.com>)
Responses Re: Convert a UNIX timestamp in a PostgreSQL INSERT statement
List pgsql-novice
On 4 Apr 2004, at 12:08, Alan T. Miller wrote:

> 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. ...

If you have a Unix-style timestamp (seconds since 1970-01-01 00:00) you
can convert it to a PostgreSQL timestamp like this:

   select timestamp '1970-01-01' + interval '953559481 seconds';

There might be a better way, but that's how I solved it.
---
Richard Brooksby <rb@ravenbrook.com>
Senior Consultant
Ravenbrook Limited <http://www.ravenbrook.com/>
PO Box 205, Cambridge CB2 1AN, United Kingdom
Voice: +44 777 9996245  Fax: +44 870 1641432


pgsql-novice by date:

Previous
From: "Alan T. Miller"
Date:
Subject: Convert a UNIX timestamp in a PostgreSQL INSERT statement
Next
From: alexandre ricciardi
Date:
Subject: problem with psql