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
Sunday, April 11, 2010
Lấy quý theo ngày tháng đưa vào
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment