02 May 2016


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:

Ence Muhidin said...

keren ini artikelnya.. boleh ya klo ada kondisi yg susah sya nanya sma admin..?
terimakasih sudah bantu

rani irsan said...

silahkan, klo emang rani bisa jawab Insya Allah.

Ence Muhidin said...
This comment has been removed by the author.
Ence Muhidin said...

mbak mohon dibantu atau masukanya
sy punya kasus yg susah terpecahkan

sy sudah kirim email rincianya
terimakasih atas waktunya

rani irsan said...

yang mana ya?

Ence Muhidin said...
This comment has been removed by the author.
Ence Muhidin said...

noreply-comment@blogger.com tu bukan email mbak
kalau bukan bolehh minta emailnya ?

rani irsan said...
This comment has been removed by the author.