Jump to content

[SOLVED] Find Number of Saturdays Between Two Dates


hoopplaya4

Recommended Posts

Hello all,

 

I'm struggling writing some code (or figuring out where to start).  I'm trying to write some code that will allow me to find the number of Saturdays between two dates.

 

For example, if I have "2/19/2009" and "2/26/09", I would know that there's one Saturday that lands between those dates.

 

Any idea on how to get started?  Thanks!

<?php 
$dt1 = "2009-02-26";
$dt2 = "2009-03-26";

$tm1 = strtotime($dt1);
$tm2 = strtotime($dt2);

$dt = Array ();
for($i=$tm1; $i<=$tm2;$i=$i+86400) {
if(date("w",$i) == 6) {
	$dt[] = date("l Y-m-d ", $i);
}
}
echo "Found ".count($dt). " Saturdays...<br>";
for($i=0;$i<count($dt);$i++) {
echo $dt[$i]."<br>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.