note 65221 deleted from function.strtotime by bjori
| From: | bjori@php.net | Date: | Thu, 27 Apr 2006 07:21:00 +0000 |
| Subject: | note 65221 deleted from function.strtotime by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109818@lists.php.net to get a copy of this message | ||
Note Submitter: hwf1984 at gmail dot com
----
I wrote this function for my little project,
it is responded to calculate the delivery date, and bah bah bah.
function myDateFun($day)
{
if($day<0)
{
die("Error in function myDateFun(): the day range is from 0 to 10\n");
}
$myWeekDay=array(0=>"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday");
$today_week_day=date("w"); //weekday of today....
$prefix="";
if(($day+1)==$today_week_day)
{
$prefix="";
}
else if(($day+1)<$today_week_day)
{
$prefix="last ";
}
else if(($day+1)>$today_week_day)
{
$prefix="next ";
if(($day+1)>($today_week_day+5)) //next week's weekday after today's weekday....
{ //example today is Wednesday, next Wednesday is today + 5
$prefix="+1 week ".$prefix; //(i.e Sat and Sun are not counted.), and next Thrusday is
} //today + 6, in php strotime, the pramater should be
} //"+1 week next Thrusday"
$str=$prefix.$myWeekDay[$day];
return $date_time=date("Y-m-d",strtotime($str));
}
for($i=0;i<10;i++)
{
echo myDateFun($i);
}