Re: Unixtime function?...

From: Roberto Mello <rmello(at)cc(dot)usu(dot)edu>
To: Richard Whittaker <richard(at)connections(dot)yk(dot)ca>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: Unixtime function?...
Date: 2001-05-02 20:11:07
Message-ID: 20010502141107.A19986@cc.usu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

On Wed, May 02, 2001 at 08:49:32AM -0700, Richard Whittaker wrote:
> Greetings:
>
> In MySQL there is a function to convert an arbitrary date/time combination
> to a Unix timestamp, which makes it really easy to perform calculations in
> PHP, since the result was always an integer... Is there a similar function
> out there for PostgresSQL or PHP?...

Some RTFM'ing comes in handy :)

I put "time" in php.net and it returned me the time function manual.

PostgreSQL has lots of functions to work with dates and times,
including to_char and to_date, with tons of functionality. In PG (and Oracle)
dates _are_ integers, even though it's not displayed to you as such:

hgcm-test=# select now();
now
------------------------
2001-05-02 14:08:40-06

hgcm-test=# select now() + 3;
?column?
------------
2001-05-05

hgcm-test=# select now() - 3;
?column?
------------
2001-04-29

Or you could use intervals:

hgcm-test=# select now() + '1 week'::interval;
?column?
------------------------
2001-05-09 14:10:18-06

There's more information in the PostgreSQL documentation.

-Roberto

--
+----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+
Roberto Mello - Computer Science, USU - http://www.brasileiro.net
http://www.sdl.usu.edu - Space Dynamics Lab, Developer
"Windows? What Windows? I use OS/2." (Bill Gates)

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Richard Whittaker 2001-05-02 20:20:24 Re: Unixtime function?...
Previous Message Adam Lang 2001-05-02 19:56:09 Re: Unixtime function?...