Thread: Unixtime function?...
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.
Attachment
At 14:11 02/05/01 -0600, Roberto Mello 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?...
Thanks,
Richard.
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.
Attachment
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?...
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) ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly
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
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
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);
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) ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly