note 92652 added to function.mktime
| From: | p2409 at hotmail dot com | Date: | Sun, 02 Aug 2009 15:49:56 +0000 |
| Subject: | note 92652 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159012@lists.php.net to get a copy of this message | ||
How to get the first and last dates of the last quarter - useful for things like tax return dates
etc. by Justin
<?php
function getLastQuarter() {
// Returns an array with a start and end date for the last quarter from todays date
// eg. If today is 23 Feb 2009, returns $x['start'] = 1 Oct 2008, $x[end] = 31 Dec
2008
$year = date("Y",mktime());
$month = date("m",mktime());
// Formula to get a quarter in the year from a month
$startmth = $month - 3 - (($month-1) % 3 );
// Fix up Jan - Feb to get LAST year's quarter dates (Oct - Dec)
if ($startmth == -2) {
$startmth+=12;
$year-=1;
}
$endmth = $startmth+2;
$last_quarter['start'] = mktime(0,0,0,$startmth,1,$year);
$last_quarter['end'] =
mktime(0,0,0,$endmth,date("t",mktime(0,0,0,$endmth,1,$year)),$year);
return $last_quarter;
}
// Example - print first and last dates of last quarter.
echo "First day of last quarter was : " .
date("d-M-Y",$lastquarter['start']) . "\n";
echo "Last day of last quarter was : " .
date("d-M-Y",$lastquarter['end']) . "\n";
// For 2 August 2009, returns:
// First day of last quarter was : 01-Apr-2009
// Last day of last quarter was : 30-Jun-2009
//
?>
----
Server IP: 117.104.162.229
Probable Submitter: 58.161.42.98 (proxied: 58.161.42.98)
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- https://master.php.net/note/edit/92652
Del: integrated -- https://master.php.net/note/delete/92652/integrated
Del: useless -- https://master.php.net/note/delete/92652/useless
Del: bad code -- https://master.php.net/note/delete/92652/bad+code
Del: spam -- https://master.php.net/note/delete/92652/spam
Del: non-english -- https://master.php.net/note/delete/92652/non-english
Del: in docs -- https://master.php.net/note/delete/92652/in+docs
Del: other reasons-- https://master.php.net/note/delete/92652
Reject -- https://master.php.net/note/reject/92652
Search -- https://master.php.net/manage/user-notes.php