note 95519 deleted from function.date by danbrown
| From: | danbrown@php.net | Date: | Thu, 07 Jan 2010 17:20:21 +0000 |
| Subject: | note 95519 deleted from function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164752@lists.php.net to get a copy of this message | ||
Note Submitter: binupillai2003 at yahoo dot com, Binu V Pillai
----
<?php
/*
This function will return week number specific for a month.
@param yyyy-mm-dd
return Interger value
eg. print getWeekNum("2010-01-15"); this will print 2. That is second week of the month
by Binu V Pillai on 2010-01-07
*/
function getWeekNum($anyDate)
{
list($yr,$mn,$dt) = split('-',$anyDate); // separate year, month and date
$timeStamp = mktime(0,0,0,$mn,$dt,$yr);
$dayCount = date('t',$timeStamp); //Count days in a month
$week=0;
for ($i=0;$i<$dayCount;$i++)//loop through all the days in a month
{
$dayNum++;
$timeStamp= mktime(0,0,0,$mn,$dayNum,$yr);//generate timestamp of each day
$day=date('D',$timeStamp);//find the dayname like Mon, Tue,Wed ..
if($day=="Mon")//noramlly week count starts from the first monday
{
$week++;
}
if($dayNum==$dt)//exit loop when it reaches the given date($anyDate)
{break;}
}
return $week;
}
print getWeekNum("2010-01-15");
?>