Difference between 2 dates in vb.net

Started by dhilipkumar, Nov 26, 2008, 05:11 PM

Previous topic - Next topic

dhilipkumar

Dim strDate() As String
        Dim difference As TimeSpan
        dim i as integer
            Dim first As DateTime = Convert.ToDateTime("1/14/2005")
            Dim second As DateTime = Convert.ToDateTime("3/25/2005")
            difference = second.Subtract(first)
        for i = 1 to difference.TotalDays
                strDate(i - 1) = first.AddDays(i)
        next



you u can use this, its another way to get

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim a As Date
        Dim b As Date
        a = TextBox1.Text
        b = TextBox2.Text
        Dim c As Integer = DateDiff(DateInterval.Day, a, b)
        Dim i As Integer
        For i = 1 To c - 1
            ListBox1.Items.Add(DateAdd(DateInterval.Day, i, a))
        Next

    End Sub