note 100390 deleted from function.date by tularis
| From: | tularis@php.net | Date: | Thu, 09 Feb 2012 20:53:21 +0000 |
| Subject: | note 100390 deleted from function.date by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185970@lists.php.net to get a copy of this message | ||
Note Submitter: Richard dot buskirk at buskirkgraphics dot com
----
Here is a very simple function to get quarterly dates.
<?php
function quarter($month='',$day='')
{
if($month != ""){$tm = mktime(0,0,0,$month,$day-1,date('Y'));}else{$tm =
date('Y-m-d H:i:s');}
$quarter = ceil(date("m", $tm)/3);
for($i=1; $i<=4; $i++)
{
$checkd = mktime(0,0,0,date('m')-$i,date('d'),date('Y'));
if(ceil(date("m", $checkd)/3) != "$quarter")
{
$meani = date("m", $checkd);
for($a=1; $a<=31; $a++)
{
$forman = mktime(0,0,0,$meani,$a,date('Y'));
if(ceil(date("m", $forman)/3) == "$quarter")
{
$first_day = date('d', $forman);
break;
}
}
break;
}
}
$current_quarter_dayone = date('Y-m-d H:i:s',
mktime(0,0,0,$meani,$first_day,date('Y')));
return $current_quarter_dayone;
}
?>
To get the current quarterly start date.
$quarter_start= quarter();
**************************************
2010-09-01 00:00:00
To find the start of a particular quarter based on a date, pass the month and day.
$quarter_start = quarter('08','30');
$quarter_end = date("Y-m-d H:i:s", strtotime($barter)-86400);
Results
**********************************
2010-06-01 00:00:00
2010-08-31 00:00:00