note 93235 deleted from function.date by tularis
| From: | tularis@php.net | Date: | Thu, 09 Feb 2012 20:55:53 +0000 |
| Subject: | note 93235 deleted from function.date by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185981@lists.php.net to get a copy of this message | ||
Note Submitter: czerpmac [at] gmail [dot] com
----
Easy way to numeric representation of a quarter from passed as parametr date.
<?php
/**
* quarterByDate()
*
* Return numeric representation of a quarter from passed free-form date.
*
* @param mixed $date
* @return integer
*/
function quarterByDate($date)
{
return (int)floor(date('m', strtotime($date)) / 3.1) + 1;
}
?>
Example:
<?php
$quarter = quarterByDate(date('Y-m-d')); // current quarter. For 2009-08-29 will be
"3"
$quarter = quarterByDate('2009-12'); // will be "4"
$quarter = quarterByDate('March'); // will be "1"
?>
I hope it will be useful.
Best regards,
S_P_E_C