Determine last quarter
| From: | Henry Hank | Date: | Wed, 20 Mar 2002 13:23:27 +0000 |
| Subject: | Determine last quarter | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-17780@lists.php.net to get a copy of this message | ||
> If anyone is interested, this is what I finally came up with. I'm not sure
> how graceful it is, but it works ;)
Here's another method... which can be condensed, but I left it expanded to
demonstrate what was going on. The trick is finding the first day of the
*next* month, and getting the previous day (
mktime(0,0,0,$start_month+3,0,$year) ), which is always the last day of the
previous month.
-Hank
<?
$quarter = ceil(date('n')/3);
$last_quarter = ($quarter==1?4:$quarter-1);
$year =($last_quarter==4?date("Y")-1:date("Y"));
$start_month = (($last_quarter-1)*3)+1;
$end_day = date("d",mktime(0,0,0,$start_month+3,0,$year));
echo "Start
Date:".date("Y-m-d",mktime(0,0,0,$start_month,1,$year))."\n";
echo "End
Date:".date("Y-m-d",mktime(0,0,0,$start_month+2,$end_day,$year))."\n";
?>
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/