hoopplaya4 Posted February 26, 2009 Share Posted February 26, 2009 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! Link to comment https://forums.phpfreaks.com/topic/147087-solved-find-number-of-saturdays-between-two-dates/ Share on other sites More sharing options...
samshel Posted February 26, 2009 Share Posted February 26, 2009 <?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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/147087-solved-find-number-of-saturdays-between-two-dates/#findComment-772193 Share on other sites More sharing options...
hoopplaya4 Posted February 27, 2009 Author Share Posted February 27, 2009 Thank you VERY much samshel. That was it! Link to comment https://forums.phpfreaks.com/topic/147087-solved-find-number-of-saturdays-between-two-dates/#findComment-772200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.