Number of sundays in a date range?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
themurph
Forum Commoner
Posts: 76
Joined: Wed Apr 19, 2006 1:56 pm
Contact:

Number of sundays in a date range?

Post 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?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
Z3RO21
Forum Contributor
Posts: 130
Joined: Thu Aug 17, 2006 8:59 am

Post by Z3RO21 »

the function strtotime() might be of useand also the PHP date() function could be of some use.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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...
Post Reply