This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm trying to figure out how to calculate the number of days between two specified dates but only on certain days of the week. The code below should work however, after I set the variable current to 7/1/2011 I then display the value of current and it doesn't reflect what day of the week it should really be.
For example, 7/1/2011 falls on a Friday or integer value 6. If you run the code shown below, what you see is the value 2 (Monday) being returned.
I am determining the integer values based on the Calendar API
When you use "7" in that position it means "August", not July. You aren't passing a month number, you are passing one of the Calendar constants. In this case you are passing Calendar.AUGUST, whose value is 7. Change the program to pass Calendar.JULY and see what happens.
Joined: Sep 12, 2011
Thanks for the speedy reply. This greenhorn missed that key information!
It's an often made mistake, and I blame Sun for this. They chose to let weekdays start at 1 (Calendar.SUNDAY), which is OK. Yet they chose to let months, which naturally start at 1, start at 0 (Calendar.JANUARY). This makes no sense whatsoever. They should either have made both start at 0 (to be consistent) or both start at 1 (again, to be consistent, but also to be more friendly).