Here is a sample for calculating number of days within specific date range for weekdays only (exclude saturday and sunday). Design UI: Code: Option Explicit Function CalculateWeekdays( ByVal startDate As Date , ByVal endDate As Date ) As Integer Dim numWeekdays As Integer Dim totalDays As Integer Dim WeekendDays As Integer Dim i As Integer numWeekdays = 0 WeekendDays = 0 totalDays = DateDiff("d", startDate, endDate) + 1 For i = 1 To totalDays If DatePart("w", startDate) = 1 Then WeekendDays = WeekendDays + 1 End If If DatePart("w", startDate) = 7 Then WeekendDays = WeekendDays + 1 End If startDate = DateAdd("d", 1, startDate) Next numWeekdays = totalDays - WeekendDays CalculateWeekdays = numWeekdays End Function Private Sub Command1_Click() Label1.Caption = CalculateWeekdays(Me.DTPicker1.Value, Me.DTPicker2.Value) End Sub Runtime: Click here if you like this article.
Sumber http://rani-irsan.blogspot.com
pop
Sabtu, 05 September 2020
Vb6: Datediff For Weekdays Only
Diterbitkan September 05, 2020
Artikel Terkait
- So many question about how to get hard disk physical serial number, and mostly answered
- Here is a sample for calculating number of days within specific date range for weekdays
- 0 Dim line As String = Lines.Dequeue Dim sz As SizeF = e
- Sometimes we don't need print preview. How to allow user print directly to a printer with
- Printing. Okay, lets see how it works. Add a button and a printdocument co
- I was working with Visual Studio 2005 and Crystal Report and the requirement is to expor
Langganan:
Posting Komentar (Atom)
EmoticonEmoticon