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

  • Thread starter Thread starter Chris Hill via .NET 247
  • Start date Start date
C

Chris Hill via .NET 247

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_numDaysInSelectedPeriod = 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!
 
Chris Hill via .NET 247 said:
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_numDaysInSelectedPeriod =
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!

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top