Re: Unixtime function?... - Mailing list pgsql-php

From Gyozo Papp
Subject Re: Unixtime function?...
Date
Msg-id 01be01c0d3c9$f7241c40$2248c5d5@jaguar
Whole thread Raw
In response to Unixtime function?...  (Richard Whittaker <richard@connections.yk.ca>)
List 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
wellas 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
ofseconds between the **Unix Epoch ** (January 1 1970) and the time specified.  


so what you need is, for example:

SELECT date_part('epoch', current_timestamp);




pgsql-php by date:

Previous
From: Roberto Mello
Date:
Subject: Re: Unixtime function?...
Next
From: Jason
Date:
Subject: psql with PHP question