469,631 Members | 1,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Workday Date Calculations

Hi all

I'm trying to calculate the number of days (or workdays) between 2 given
dates that do not include weekend days or public holidays
(public holidays are user defined from a dbase, have a start date & an end
date & may span a weekend)
If a start date (workday) & an end date (workday) are on the same day then
the number of workdays will equal zero

Some eg's.

Start Date - 2-Dec-04 (Thurs)
End date 2-Dec-04 (Thurs)
No of working days = 0

Start Date - 2-Dec-04 (Thurs)
End date 3-Dec-04 (Fri)
No of working days = 1

Start Date - 2-Dec-04 (Thurs)
End date - 10-Dec-04 (Fri)
No of working days = 6 (8 total days minus 2 weekend days)

Start Date - 2-Dec-04 (Thurs)
End date - 22-Dec-04 (Wed)
Public Holiday Start Date - 17-Dec-04 (Fri)
Public Holiday End Date - 20-Dec-04 (Mon)
No of working days = 12 (20 total days minus 6 weekend days minus only 2 of
the Public Holiday days as 2 fell on a weekend)

Start Date - 2-Dec-04 (Thurs)
End date - 17-Dec-04 (Fri)
Public Holiday Start Date - 17-Dec-04 (Fri)
Public Holiday End Date - 20-Dec-04 (Mon)
No of working days = 10 (15 total days minus 4 weekend days minus only 1 of
the Public Holiday days as the End date fell on the 1st day of the Public
Holday)

I've been experimenting with timespans & datediff but just can't seem to get
it off the ground

Has anyone done something similar or could point me in the right direction ?

Regards
Wayne

Nov 21 '05 #1
1 5775
Wayne,

Really fun stuff, I assume (hope for you) you get a lot of better sollutions
than this.

This is quickly made, when you go in the direction of the timespan, know
than that it has a limited value.

Hollidays are not in the Framework. However they are in office.

I made a table with one holliday and because this year chrismass as well as
newyear are on saterday sunday I took tomorrow as a holliday in this sample

\\\start time sample is 2004, dec, 2
Public Class Hello
Public Shared Sub main()
Dim DateToReach As DateTime = New DateTime(2005, 1, 1)
Dim hollidays(0) As DateTime
hollidays(0) = New DateTime(2004, 12, 3) 'just for the test
Dim count As Integer
Dim Testdate As DateTime = Now
Do Until Testdate.Date = DateToReach.Date
If Testdate.DayOfWeek <> DayOfWeek.Sunday AndAlso _
Testdate.DayOfWeek <> DayOfWeek.Saturday Then
Dim holliday As Boolean = False
For Each td As Date In hollidays
If Testdate.Date = td.Date Then
holliday = True
Exit For
End If
Next
If holliday = False Then
count += 1
End If
End If
Testdate = Testdate.AddDays(1)
Loop
MessageBox.Show(count.ToString)
End Sub
///

I hope this helps something?

Cor

"Wayne" <wg****@hotmail.com>
Hi all

I'm trying to calculate the number of days (or workdays) between 2 given
dates that do not include weekend days or public holidays
(public holidays are user defined from a dbase, have a start date & an end
date & may span a weekend)
If a start date (workday) & an end date (workday) are on the same day then
the number of workdays will equal zero

Some eg's.

Start Date - 2-Dec-04 (Thurs)
End date 2-Dec-04 (Thurs)
No of working days = 0

Start Date - 2-Dec-04 (Thurs)
End date 3-Dec-04 (Fri)
No of working days = 1

Start Date - 2-Dec-04 (Thurs)
End date - 10-Dec-04 (Fri)
No of working days = 6 (8 total days minus 2 weekend days)

Start Date - 2-Dec-04 (Thurs)
End date - 22-Dec-04 (Wed)
Public Holiday Start Date - 17-Dec-04 (Fri)
Public Holiday End Date - 20-Dec-04 (Mon)
No of working days = 12 (20 total days minus 6 weekend days minus only 2
of
the Public Holiday days as 2 fell on a weekend)

Start Date - 2-Dec-04 (Thurs)
End date - 17-Dec-04 (Fri)
Public Holiday Start Date - 17-Dec-04 (Fri)
Public Holiday End Date - 20-Dec-04 (Mon)
No of working days = 10 (15 total days minus 4 weekend days minus only 1
of
the Public Holiday days as the End date fell on the 1st day of the Public
Holday)

I've been experimenting with timespans & datediff but just can't seem to
get
it off the ground

Has anyone done something similar or could point me in the right direction
?

Regards
Wayne

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by androtech | last post: by
11 posts views Thread by lduperval | last post: by
1 post views Thread by SirPoonga | last post: by
3 posts views Thread by Glencannon4424 via AccessMonster.com | last post: by
8 posts views Thread by Charlie Brookhart | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.