By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,040 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,040 IT Pros & Developers. It's quick & easy.

How do I calculate the number of weekdays between 2 dates :?

P: n/a
Hi

I'm a jnr developer in need of desparate help. Can anyone point me in the right direction for this problem:

I calculate the number of days between 2 user defined dates like this:
Dim DaysInRange As Long

DaysInRange = DateDiff("d", Me.dtp_firstdate.Text, Me.dtp_lastdate.Text) + 1

mod_rptStaffCaseloadAnalysis.p_numDaysInSelectedPe riod = DaysInRange

What I need to do now, is work out the number of weekdays (Mon-Fri) between the dates selected by the user.

I am completely stumped.

Can anyone provide some pointers?

Thanks!

--------------------------------
From: Chris Hill

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>h2uGpHNzI0OuwyE/NFvrug==</Id>
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Chris Hill via .NET 247" <an*******@dotnet247.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
Hi

I'm a jnr developer in need of desparate help. Can anyone point me in the
right direction for this problem:

I calculate the number of days between 2 user defined dates like this:
Dim DaysInRange As Long

DaysInRange = DateDiff("d", Me.dtp_firstdate.Text,
Me.dtp_lastdate.Text) + 1

mod_rptStaffCaseloadAnalysis.p_numDaysInSelectedPe riod =
DaysInRange

What I need to do now, is work out the number of weekdays (Mon-Fri)
between the dates selected by the user.

I am completely stumped.

Can anyone provide some pointers?

Thanks!

--------------------------------
From: Chris Hill

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>h2uGpHNzI0OuwyE/NFvrug==</Id>


You could simply iterate the dates like (air code):

Dim temp as DateTime = Me.dtp_firstdate.Value
Dim count as Integer

While temp <= Me.dtp_lastdate.Value
Select Case temp.DayOfWeek

Case DayOfWeek.Saturday, DayOfWeek.Sunday 'do nuthing

Case Else

count += 1

End Select

temp = DateAdd("d", 1, temp)

End While
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.