Re: Convert a UNIX timestamp in a PostgreSQL INSERT statement

From: Richard Brooksby <rb(at)ravenbrook(dot)com>
To: "Alan T(dot) Miller" <amiller(at)hollywood101(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Convert a UNIX timestamp in a PostgreSQL INSERT statement
Date: 2004-04-04 14:14:03
Message-ID: 53A6CEBC-8642-11D8-97F4-000393D3C042@ravenbrook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)ravenbrook(dot)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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message alexandre ricciardi 2004-04-04 14:32:42 problem with psql
Previous Message Alan T. Miller 2004-04-04 11:08:50 Convert a UNIX timestamp in a PostgreSQL INSERT statement