开发者

how get calc saturday+monday in range date

i hope some help to me ... i am trouble with some code IN PHP ,maybe you can see function about this :

I need to check 开发者_运维知识库is there on Saturday in one period ($date_start ,$date_end ) so : input : $date_Start (ex: "2010-07-01") $date_end (ex: "2010-07-12")

output : total saturday : 2 in your range date

but the way thanks before

JOKONARDI


Efficient implementation with no loops for number of Saturdays in the range:

$d1 = new DateTime("2010-07-01"); //including
$d2 = new DateTime("2010-07-12"); //excluding
$diff = $d2->diff($d1);
$days = $diff->format("%a");
$num = floor($days / 7);
$remaining = $days % 7;
$d = $d1->format("w");
if ($d + $remaining > 6)
    $num++;

//result in $num
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜