Get the number of calendar weeks between 2 dates in C#
Posted
by Phil Scholtes
on Stack Overflow
See other posts from Stack Overflow
or by Phil Scholtes
Published on 2010-06-17T21:47:02Z
Indexed on
2010/06/17
21:53 UTC
Read the original article
Hit count: 331
For the purposes of this question, let's assume the user will be from the US and will use the standard Gregorian calendar. So, a calendar week starts on Sunday and ends on Saturday.
What I'm trying to do is determine the number of calendar weeks that exist between two dates. A perfect example of my problem exists in October 2010. Between 10/16 and 10/31 there are 4 calendar weeks.
View a picture of October 2010
- October 10 - October 16
- October 17 - October 23
- October 24 - October 30
- October 31 - November 6
I'd prefer to stay away from any hardcoded logic like:
if (Day == DayOfWeek.Saturday && LastDayOfMonth == 31) { ... }
Can anyone think of a logical way to do this?
© Stack Overflow or respective owner