Page 1 of 1
Number of sundays in a date range?
Posted: Fri Dec 29, 2006 5:09 pm
by themurph
Can anyone share a snippet of code that, given a date range like
01/19/2006 - 02/19/2006, will return the number of sundays
(or mondays, etc) within that range?
Posted: Fri Dec 29, 2006 5:31 pm
by timvw
you could try to think of an algorithm that finds the first sunday, and then move 7 days further untill you've reached the end date... In case of any problems, let us know...
Posted: Fri Dec 29, 2006 7:35 pm
by Z3RO21
the function strtotime() might be of useand also the PHP date() function could be of some use.
Posted: Fri Dec 29, 2006 9:31 pm
by Kieran Huggins
Hint:
strtotime() makes a timestamp
the use the date() function and some of the following formats:
"z"
The day of the year (starting from 0)
0 through 365
"N"
ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)
1 (for Monday) through 7 (for Sunday)
Then a little division...