RE: [PHP] Sorting db entries by Year-Month

From: Date: Wed, 24 Jul 2002 02:29:50 +0000
Subject: RE: [PHP] Sorting db entries by Year-Month
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-109191@lists.php.net to get a copy of this message
> further research indicates that for PG I could trysomething like: > > SELECT EXTRACT(MONTH FROM TIMESTAMP) I'm sure there is a NOW() or TIME() function in PG that returns the current date/time. Then you could do this: SELECT * FROM your_table WHERE EXTRACT(MONTH FROM your_column) = EXTRACT(MONTH FROM PG_CURRENT_TIME_FUNCTION()); > $today = getdate(); >  $start = $today['year'] . '-' . $today['mon'] . '-' . > '01'; >  $end  =  $today['year'] . '-' . $today['mon'] . '-' > . '31'; > > "SELECT * FROM guest WHERE pdate BETWEEN {$start} AND {$end}"; > > but PG doesn't like my format of $pdate as type date, since the result for > $start and $end seems to result in type integer. Sigh. I think PG uses the unix timestamp format, the number of seconds since Jan 1, 1970 or something. You could use a combination of date() and mktime() and maybe even strtotime() to figure the unix timestamp of the current month's start and end, then use the BETWEEN SQL given above... ---John Holmes...

« previous php.general (#109191) next »