![Embarassed :oops:](./images/smilies/icon_redface.gif)
how can i know if there are a sundy between 2 dates?
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 8
- Joined: Thu Jul 19, 2007 6:10 am
how can i know if there are a sundy between 2 dates?
how can i know if there are a sundy between 2 dates? i have a condition for calculating a indicator, for exemple: date1=01/07/07 et date2=19/07/07, how can i know there are a sundy between date1 and date2? i have a table of "day" to know "what day is today?" how can i do it? my english is terrible, i am sorry ![Embarassed :oops:](./images/smilies/icon_redface.gif)
![Embarassed :oops:](./images/smilies/icon_redface.gif)
Welcome aboard! You need to calculate if the difference in dates is greater than 6, or if less than 6 the day of the week of the starting date plus the difference will include a Sunday. Any date separation greater than 6 must mean that one of the dates is a Sunday or that the number of days is greater than a week and therefore includes Sundays.
The simple algorithm is:
StartDate.DayOfWeek + (EndDate - StartDate) > 6
If 2007-01-01 is a Monday, and Monday is day of week #1 then:
1 + (2007-01-07 - 2007-01-01) = 7 (must have included a Sunday)
1 + (2007-01-04 - 2007-01-01) = 4 (could not have included a Sunday)
4 + (2007-01-04 - 2007-01-04) = 4 (could not have included a Sunday)
4 + (2007-01-07 - 2007-01-04) = 7 (must have included a Sunday)
4 + (2007-01-07 - 2007-01-04) = 7 (must have included a Sunday)
6 + (2007-01-07 - 2007-01-06) = 7 (must have included a Sunday)
1 + (2007-01-23 - 2007-01-01) = 23 (must have included a Sunday)
The simple algorithm is:
StartDate.DayOfWeek + (EndDate - StartDate) > 6
If 2007-01-01 is a Monday, and Monday is day of week #1 then:
1 + (2007-01-07 - 2007-01-01) = 7 (must have included a Sunday)
1 + (2007-01-04 - 2007-01-01) = 4 (could not have included a Sunday)
4 + (2007-01-04 - 2007-01-04) = 4 (could not have included a Sunday)
4 + (2007-01-07 - 2007-01-04) = 7 (must have included a Sunday)
4 + (2007-01-07 - 2007-01-04) = 7 (must have included a Sunday)
6 + (2007-01-07 - 2007-01-06) = 7 (must have included a Sunday)
1 + (2007-01-23 - 2007-01-01) = 23 (must have included a Sunday)
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
-
- Participant
- Posts: 8
- Joined: Thu Jul 19, 2007 6:10 am