Re: Finding # of weekdays between 2 dates..

From: Date: Fri, 27 Dec 2002 07:48:03 +0000
Subject: Re: Finding # of weekdays between 2 dates..
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-129413@lists.php.net to get a copy of this message
WFM: $nowdate = mktime(0, 0, 0, 4, 1, 2002); $futuredate = mktime(0, 0, 0, 5, 2, 2002); echo weekdaysBetween ($nowdate,$futuredate,2); I get 5 Chad Day wrote:
I found this function in the list archives while searching on how to find the number of a weekday (say, Tuesdays) between 2 dates.. function weekdaysBetween ($timestamp1, $timestamp2, $weekday) { return floor(intval(($timestamp2 - $timestamp1) / 86400) / 7)
     + ((date('w', $timestamp1) <= $weekday) ? 1 : 0);
} Sometimes it works, but I've come across a date while testing this that doesn't work, which makes me think there is some bug in the function that I'm not seeing. The 2 dates I am trying are: 01-04-2002 and 02-05-2002 There should be 5 Tuesdays: 01-08-2002 01-15-2002 01-22-2002 01-29-2002 02-05-2002 Yet the script only returns 4, leaving off 02-05-2002. $nowdate = mktime(0, 0, 0, $STARTMONTH, $STARTDAY, $STARTYEAR); $futuredate = mktime(0, 0, 0, $ENDMONTH, $ENDDAY, $ENDYEAR); That's how I'm generating the time stamps to pass to the function, and I've confirmed the dates I've entered are correct.. echo weekdaysBetween($nowdate, $futuredate, 2); Returns 4 .. can anyone assist? Thanks, Chad


« previous php.general (#129413) next »