Jump to content

Day Count


jeeva

Recommended Posts

Yeah I had some spare time so I wrote the script for you. I tested a few months, worked... So hopefully it's all good:

 

<?php

//The month and year
$month = "May";
$year = 2008;

//Get the number of days for the selected month...
$numberOfDaysInMonth = date("t", strtotime($month));

//First find out the first day of the month... 0 (sunday) and so on...
$firstDayOfMonth = date("w", strtotime("1 {$month} {$year}"));

//Set numberOfFridays to a default of 0
$numberOfFridays = 0;

//Now we need to loop through every day of the month and check if it is a friday
for($i = 1, $s = $firstDayOfMonth; $i <= $numberOfDaysInMonth; $i++){
if($s == 5){
	//5 is friday, so when s == 5 it is a friday. So we add 1 to the friday tally.
	$numberOfFridays += 1;
}

if($s == 6){
	//We have reached Saturday, start again...
	$s = 0;
}else{
	$s += 1; //Add one to the day...
}
}

echo "In {$month} of {$year} there are {$numberOfFridays} Fridays!";

?>

 

Hope it helps!

Link to comment
https://forums.phpfreaks.com/topic/118071-day-count/#findComment-607405
Share on other sites

LOOL, also had some spare time.. theirs probably a better why but try this

<?php
$year = 2008;
$month = 1; //Aug
$day = 1;
$startDate = mktime(0, 0, 0, $month, $day, $year);
$NoD = date( "t", $startDate);

While(date( "D", $startDate) != "Fri") //find first Friday
{
$day++;
$startDate = mktime(0, 0, 0, $month, $day, $year);
}
$day--;
$days = ceil(($NoD-$day)/7);
echo "$days Fridays";

?>

Link to comment
https://forums.phpfreaks.com/topic/118071-day-count/#findComment-607411
Share on other sites

Thanks frnds,

 

I got this simple code ....

<?php
       $month = 5;
       $year  = 2008;
       $sd = mktime(0,0,0,$month,1,$year);      
       $n = date('N',$sd);
       $fr = 5;           //day of the week
       $frd = $fr-$n;   
      $nof = 4;    //default no.of fridays in a month

      $ad1 = mktime(0,0,0,$month,$frd+1+28,$year);  
  
      if(date('m',$ad1)==$month)
       $nof++;
   
      echo $nof." fridays for the month ".date('M-Y',$sd);
    
    ?>

 

Thanks

Jeeva

Link to comment
https://forums.phpfreaks.com/topic/118071-day-count/#findComment-607435
Share on other sites

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.