tags:

views:

18

answers:

1

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

A: 

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
Artefacto
thanks friend.. nice solution and this is top site for reference for me :)
jokonardi
but i am so sorry ,result $num = 859actually ,value = 2
jokonardi
so ,you can see more code ?
jokonardi
@jok It gives 2. See here: http://codepad.viper-7.com/QgV8f7
Artefacto
hm...maybe can you give me some function diff ?i read your code using this :diff($d1)
jokonardi
my result now NAN this is my code :<?php$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++;}echo"$num";?>
jokonardi