Rani pernah bahas gimana cara menghitung selisih waktu hari kerja, karena ada pertanyaan dari reader gimana klo menambahkan jumlah hari tapi hanya dengan hari kerja saja (weekdays). Langsung aja kita jawab dengan contoh ya.
Design UI:
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "From:"
Label2.Text = "Add day(s):"
Label3.Text = "To:"
Button1.Text = "Add Weekday"
End Sub
Public Shared Function AddWeekdays(ByVal startDate As Date, _
ByVal interval As Integer) As Date
Dim curDate As Date = startDate
Dim i As Integer = 0
Do While i < interval
curDate = curDate.AddDays(1)
If curDate.DayOfWeek <> DayOfWeek.Saturday And _
curDate.DayOfWeek <> DayOfWeek.Sunday Then
i = i + 1
End If
Loop
Return curDate
End Function
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
DateTimePicker2.Value = AddWeekdays(DateTimePicker1.Value, _
CDbl(TextBox1.Text))
End Sub
End Class
Runtime:
Click here if you like this article.
8 Comments
terimakasih sudah bantu
sy punya kasus yg susah terpecahkan
sy sudah kirim email rincianya
terimakasih atas waktunya
kalau bukan bolehh minta emailnya ?