Re: Unixtime function?...

From: "Gyozo Papp" <pgerzson(at)freestart(dot)hu>
To: <pgsql-php(at)postgresql(dot)org>, "Richard Whittaker" <richard(at)connections(dot)yk(dot)ca>
Subject: Re: Unixtime function?...
Date: 2001-05-03 11:33:38
Message-ID: 01be01c0d3c9$f7241c40$2248c5d5@jaguar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php


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

yes,there is a function called :
- date_part(text, timestamp),
and another :
- date_trunc(text, timestamp),

(from the manual of postgres v7.0.2)

For the date_part and date_trunc functions, arguments can be `year', `month', `day', `hour', `minute', and `second', as well as the more specialized quantities `decade', `century', `millennium', `millisecond', and `microsecond'. date_part allows `dow' to return day of week, 'week' to return the ISO-defined week of year,
and **`epoch'** to return seconds since 1970 (for timestamp) or 'epoch' to return total elapsed seconds (for interval).

(from the manual of PHP )
int mktime (int hour, int minute, int second, int month, int day, int year [, int is_dst])

Returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the **Unix Epoch ** (January 1 1970) and the time specified.

so what you need is, for example:

SELECT date_part('epoch', current_timestamp);

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Andy Howarth 2001-05-03 11:35:24 Problems compiling 7.1 with TCL support on Solaris 7
Previous Message Roberto Mello 2001-05-02 20:44:04 Re: Unixtime function?...