imagene that u have two dates, example: $inicio ="2008-10-10"; $fim ="2008-10-16"; I need a function that when I insert the two dates, the funcions returns the number of weekends that exist between the two date, I would be very greatfull for the help , tks
Just a tip if I may: 1 - Transform both dates into Unix timestamps (difference in seconds from January, 1st of 1970), like this: $difinicio=strtotime($inicio.' 00:00:00'); $diffim=strtotime($fim.' 00:00:00'); PHP: 2 - check if $difinicio is a Sunday. If it is, add one to $weekcounter (counting sundays is the same as counting weekends). A Sunday is when date("w", $difinicio) == 0 if (date("w", $difinicio) == 0) { $weekcounter++; } PHP: 3 - Add one day to $difinicio like this: $difinicio= strtotime('+1 day',strtotime(date("Y",$difinicio).'-'.date("m",$difinicio).'-'.date("d",$difinicio).' 00:00:00')); PHP: 4 - Repeat step 2 and 3 until $difinicio = $diffim 5 - $weekcounter should be your result. This should work and I hope this helps. You're a portuguese right? boa sorte then!