Kamis, 29 Desember 2016

Fungsi Menghitung Durasi Bulan dan Hari

  Function bacaUsia()
        On Error Resume Next
        Dim tgl1, tgl2 As String
        tgl1 = txtTanggalLahir.Text
        tgl2 = Now.Date
        Console.WriteLine("NOW=" & tgl2)
        Console.WriteLine("CHOOSE =" & tgl1)

        Dim ctgl1, ctgl2 As Date
        ctgl1 = CDate(tgl1)
        ctgl2 = CDate(tgl2)

        Dim selt, selb, selh As Integer
       selh = DateDiff(DateInterval.Day, ctgl1, ctgl2)
   
        Dim d As Date = Date.FromOADate(selh)
        Dim hs = d.ToString
        hs = hs.Replace(" 00:00:00", "")
        Dim ar() As String
        ar = hs.Split("/")
        Dim tothari As String = ar(0)
        Dim totbulan = Convert.ToInt32(ar(1)) + ((Convert.ToInt32(ar(2)) - 1900) * 12)
        Console.WriteLine(hs & "#totbulan=" & totbulan & ", " & tothari)
        Console.WriteLine("=====================================")
        '14/04/1901 00:00:00

        txtBulan.Text = CStr(totbulan)
        txtHari.Text = tothari


    End Function




Tidak ada komentar:

Posting Komentar