note 95519 added to function.date
| From: | binupillai2003 at yahoo dot com | Date: | Thu, 07 Jan 2010 09:07:30 +0000 |
| Subject: | note 95519 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164724@lists.php.net to get a copy of this message | ||
<?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");
?>
----
Server IP: 69.147.83.197
Probable Submitter: 125.17.241.229
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/95519
Del: integrated -- https://master.php.net/note/delete/95519/integrated
Del: useless -- https://master.php.net/note/delete/95519/useless
Del: bad code -- https://master.php.net/note/delete/95519/bad+code
Del: spam -- https://master.php.net/note/delete/95519/spam
Del: non-english -- https://master.php.net/note/delete/95519/non-english
Del: in docs -- https://master.php.net/note/delete/95519/in+docs
Del: other reasons-- https://master.php.net/note/delete/95519
Reject -- https://master.php.net/note/reject/95519
Search -- https://master.php.net/manage/user-notes.php