[quote=17087:@Tim Hare]“much more code”?? One or two lines at most.
dim theDate as New Date
dim tomorrow as New Date(theDate)
tomorrow.Day = tomorrow.Day + 1
dim yesterday as New Date(theDate)
yesterday.Day = yesterday.Day - 1[/quote]
An you could shorten it still to 4 lines of code
Dim tomorrow as New Date
Dim yesterday as New Date
I guess a simple, holiday ignorant solution, would be as easy as:
Sub AddBusinessDays(Extends d As Date, count As Integer)
For i As Integer = 1 To count
d.Day = d.Day + 1
If d.DayOfWeek = 7 Then
d.Day = d.Day + 2
End If
Next
End Sub
I’d calculate it up front since you know that every 5 days would require 2 more. Without testing, something like this…
count = count + d.DayOfWeek - 2
d.Day = d.Day - d.DayOfWeek + 2 // I'm looking to bring it back to the Monday so this math might be off
diff = count \\ 5
count = count + ( diff * 2 )
d.Day = d.Day + count
Then the question is how to deal with the case when d falls on a weekend. I’ll take a look at those links later and maybe build it into my module. I’ll report back either way.
This calls for a subclass of Date, I think. That subclass would have properties to hold holidays and business start hour/end hour, and work week start day/end day, then implement things like BusinessDay, BusinessHour, BusinessMinute, etc. My thinking is that a date that lands on a non-work date (weekend or holiday) would automatically be incremented to the next business date. So, for example, if you did something like this:
dim d as Date = SomeSaturday
dim bd as new BusinessDate( d ) // Would give you the following Monday
[quote=17188:@Kem Tekinay]This calls for a subclass of Date, I think. That subclass would have properties to hold holidays and business start hour/end hour, and work week start day/end day, then implement things like BusinessDay, BusinessHour, BusinessMinute, etc. My thinking is that a date that lands on a non-work date (weekend or holiday) would automatically be incremented to the next business date.
…
An interesting exercise…[/quote]
That makes sense, and yeah, things like this are fun!
If you wanted to advance, say, 100 business days, I’d expect that to take much longer than the method I proposed. With 100 days, you know you’d have to add around 40 additional days for the weekends, so you wouldn’t need to loop.
It would be 100 \ 5 , not 7. You want to advance it by 100 business days, so that’s 20 five-day weeks. Two weekend days for each of those = 40 additional days. So 100 business days = 140 days.
I’m not getting the last posts here, so time to clear my cache and/or cookies, I think.
OK, I can’t see the last post in this conversation until I or someone else posts something else. Then the formerly last post appears, but the new one does not.
I wrote a program called CleanHaven. One of its many functions is to determine the ‘Number of days between two dates’. There is a popup option for three items: total number of days, number of weekends and number of week days i.e. business days.
getDaysDifference(startDate As date, endDate As date, sourceDates As String, Type As String) 'sourceDates is if you provide the dates tab-delimited