pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedUnixtime function?...
7+ messages / 5 participants
[nested] [flat]
* Unixtime function?...
@ 2001-05-02 15:49 Richard Whittaker <richard@connections.yk.ca>
2001-05-02 19:56 ` Re: Unixtime function?... Adam Lang <aalang@rutgersinsurance.com>
2001-05-02 20:11 ` Re: Unixtime function?... Roberto Mello <rmello@cc.usu.edu>
2001-05-02 20:20 ` Re: Unixtime function?... Richard Whittaker <richard@connections.yk.ca>
2001-05-02 20:23 ` Re: Unixtime function?... Matthew Kolb <muk@phaedrus.gaslightmedia.com>
2001-05-03 11:33 ` Re: Unixtime function?... Gyozo Papp <pgerzson@freestart.hu>
0 siblings, 5 replies; 7+ messages in thread
From: Richard Whittaker @ 2001-05-02 15:49 UTC (permalink / raw)
To: 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?...
Thanks kindly,
Richard W.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Unixtime function?...
2001-05-02 15:49 Unixtime function?... Richard Whittaker <richard@connections.yk.ca>
@ 2001-05-02 19:56 ` Adam Lang <aalang@rutgersinsurance.com>
4 siblings, 0 replies; 7+ messages in thread
From: Adam Lang @ 2001-05-02 19:56 UTC (permalink / raw)
To: pgsql-php
mktime will take time and date and give a timestamp
getdate takes a timestamp and returns an array holding the information you
want
For more details, go to php.net and do a search on the specific functions.
The pages are very details and I'm pretty sure this is what you are looking
for.
Adam Lang
Systems Engineer
Rutgers Casualty Insurance Company
http://www.rutgersinsurance.com
----- Original Message -----
From: "Richard Whittaker" <richard@connections.yk.ca>
To: <pgsql-php@postgresql.org>
Sent: Wednesday, May 02, 2001 11:49 AM
Subject: [PHP] Unixtime function?...
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Unixtime function?...
2001-05-02 15:49 Unixtime function?... Richard Whittaker <richard@connections.yk.ca>
@ 2001-05-02 20:11 ` Roberto Mello <rmello@cc.usu.edu>
4 siblings, 0 replies; 7+ messages in thread
From: Roberto Mello @ 2001-05-02 20:11 UTC (permalink / raw)
To: Richard Whittaker <richard@connections.yk.ca>; +Cc: 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)
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Unixtime function?...
2001-05-02 15:49 Unixtime function?... Richard Whittaker <richard@connections.yk.ca>
@ 2001-05-02 20:20 ` Richard Whittaker <richard@connections.yk.ca>
2001-05-02 20:44 ` Re: Unixtime function?... Roberto Mello <rmello@cc.usu.edu>
4 siblings, 1 reply; 7+ messages in thread
From: Richard Whittaker @ 2001-05-02 20:20 UTC (permalink / raw)
To: Roberto Mello <rmello@cc.usu.edu>; +Cc: pgsql-php
At 14:11 02/05/01 -0600, Roberto Mello wrote:
> Some RTFM'ing comes in handy :)
> 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:
Allright, so given that, how do I get the number of seconds between two
arbitrary date/time values or even just time values, and pass that back to
PHP?...
Thanks,
Richard.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Unixtime function?...
2001-05-02 15:49 Unixtime function?... Richard Whittaker <richard@connections.yk.ca>
2001-05-02 20:20 ` Re: Unixtime function?... Richard Whittaker <richard@connections.yk.ca>
@ 2001-05-02 20:44 ` Roberto Mello <rmello@cc.usu.edu>
0 siblings, 0 replies; 7+ messages in thread
From: Roberto Mello @ 2001-05-02 20:44 UTC (permalink / raw)
To: Richard Whittaker <richard@connections.yk.ca>; +Cc: pgsql-php
On Wed, May 02, 2001 at 01:20:24PM -0700, Richard Whittaker wrote:
>
> Allright, so given that, how do I get the number of seconds between two
> arbitrary date/time values or even just time values, and pass that back to
> PHP?...
You're not going to even try to find this information in the docs????
http://postgresql.readysetnet.com/users-lounge/docs/7.1/user/functions-datetime.html
hgcm-test=# select extract(epoch from timestamp 'now()');
date_part
-----------
988836181
-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
DOS = Damned Old Software
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Unixtime function?...
2001-05-02 15:49 Unixtime function?... Richard Whittaker <richard@connections.yk.ca>
@ 2001-05-02 20:23 ` Matthew Kolb <muk@phaedrus.gaslightmedia.com>
4 siblings, 0 replies; 7+ messages in thread
From: Matthew Kolb @ 2001-05-02 20:23 UTC (permalink / raw)
To: pgsql-php
On Wed, May 02, 2001 at 08:49:32AM -0700, Richard Whittaker wrote:
> 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?...
well in php you can use date(),
http://www.php.net/manual/en/function.date.php
and all the time functions in php
http://www.php.net/manual/en/ref.datetime.php
and in postgres you can use functions like date_part()
http://www.postgresql.org/docs/aw_pgsql_book/node92.html#7786
that would be a good start.
./muk
--
Matthew Kolb
muk@phaedrus.gaslightmedia.com
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Unixtime function?...
2001-05-02 15:49 Unixtime function?... Richard Whittaker <richard@connections.yk.ca>
@ 2001-05-03 11:33 ` Gyozo Papp <pgerzson@freestart.hu>
4 siblings, 0 replies; 7+ messages in thread
From: Gyozo Papp @ 2001-05-03 11:33 UTC (permalink / raw)
To: pgsql-php; Richard Whittaker <richard@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);
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2001-05-03 11:33 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-05-02 15:49 Unixtime function?... Richard Whittaker <richard@connections.yk.ca>
2001-05-02 19:56 ` Adam Lang <aalang@rutgersinsurance.com>
2001-05-02 20:11 ` Roberto Mello <rmello@cc.usu.edu>
2001-05-02 20:20 ` Richard Whittaker <richard@connections.yk.ca>
2001-05-02 20:44 ` Roberto Mello <rmello@cc.usu.edu>
2001-05-02 20:23 ` Matthew Kolb <muk@phaedrus.gaslightmedia.com>
2001-05-03 11:33 ` Gyozo Papp <pgerzson@freestart.hu>
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