vb Code:
Sub CountDayOfWeekA(ByVal fromDate As Date, ByVal toDate As Date)
Dim theCounter As New Dictionary(Of DayOfWeek, Integer)
Dim d As Date = fromDate
Dim ctr As Integer = 0
Dim sb As New System.Text.StringBuilder
sb.Append("Your start date was a " & fromDate.DayOfWeek.ToString & ".")
sb.Append(ControlChars.CrLf & ControlChars.CrLf)
Do While d <= toDate
If theCounter.ContainsKey(d.DayOfWeek) Then
theCounter(d.DayOfWeek) += 1
Else
theCounter.Add(d.DayOfWeek, 1)
End If
d = d.AddDays(1)
ctr += 1
Loop
For Each entry As KeyValuePair(Of DayOfWeek, Integer) In theCounter
sb.AppendFormat("{0} {1}s" & vbNewLine, entry.Value, entry.Key)
Next
sb.Append(ControlChars.CrLf)
sb.Append("There are " & Format(ctr, "###,###,###,###,###") & " days between then and your end date.")
sb.Append(ControlChars.CrLf & ControlChars.CrLf)
Dim elapsedHours As Long = ((ctr - 2) * 24) + (24 - DateAndTime.DateDiff(DateInterval.Hour, CType("00:00:00", Date), CType(dtp1.Value.TimeOfDay.ToString, Date))) + DateAndTime.DateDiff(DateInterval.Hour, CType("00:00:00", Date), CType(dtp3.Value.TimeOfDay.ToString, Date))
sb.Append("or " & Format(elapsedHours, "###,###,###,###,###") & " hours (approx.)")
sb.Append(ControlChars.CrLf)
Dim elapsedMinutes As Long = ((ctr - 2) * 1440) + (1440 - DateAndTime.DateDiff(DateInterval.Minute, CType("00:00:00", Date), CType(dtp1.Value.TimeOfDay.ToString, Date))) + DateAndTime.DateDiff(DateInterval.Minute, CType("00:00:00", Date), CType(dtp3.Value.TimeOfDay.ToString, Date))
sb.Append("or " & Format(elapsedMinutes, "###,###,###,###,###") & " minutes (approx.)")
sb.Append(ControlChars.CrLf)
Dim elapsedSeconds As Long = ((ctr - 2) * 86400) + (86400 - DateAndTime.DateDiff(DateInterval.Second, CType("00:00:00", Date), CType(dtp1.Value.TimeOfDay.ToString, Date))) + DateAndTime.DateDiff(DateInterval.Second, CType("00:00:00", Date), CType(dtp3.Value.TimeOfDay.ToString, Date))
sb.Append("or " & Format(elapsedSeconds, "###,###,###,###,###") & " seconds (approx.)")
MessageBox.Show(sb.ToString, "Summary", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False)
End Sub