pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gyozo Papp <pgerzson@freestart.hu>
To: pgsql-php@postgresql.org
To: Richard Whittaker <richard@connections.yk.ca>
Subject: Re: Unixtime function?...
Date: Thu, 3 May 2001 13:33:38 +0200
Message-ID: <01be01c0d3c9$f7241c40$2248c5d5@jaguar> (raw)
References: <5.0.2.1.0.20010502084535.0413d790@mekong.connections.yk.ca>


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);






view thread (7+ messages)

Message-ID: <01be01c0d3c9$f7241c40$2248c5d5@jaguar>
Permalink:  ../01be01c0d3c9$f7241c40$2248c5d5@jaguar/
Also on:    postgresql.org/message-id/01be01c0d3c9$f7241c40$2248c5d5@jaguar

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: pgerzson@freestart.hu, richard@connections.yk.ca
  Subject: Re: Unixtime function?...
  In-Reply-To: <01be01c0d3c9$f7241c40$2248c5d5@jaguar>
  References: <5.0.2.1.0.20010502084535.0413d790@mekong.connections.yk.ca> <01be01c0d3c9$f7241c40$2248c5d5@jaguar>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox