Get list of dates in a range - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

get list of dates in vb.net

For this tutorial we need a LisBox, 2 DateTimePicker and a Button.
When a user select a range of date and click the button, every single date that occurs in that range will be added to the listbox

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button1.Click
        Dim date1 As Date
        Dim date2 As Date

        date1 = DateTimePicker1.Text
        date2 = DateTimePicker2.Text
        If date1 = date2 Then

        ElseIf date1 > date2 Then
            MsgBox("Please Enter a Valid Date Range")

        Else
            ListBox1.Items.Add(date1)
            Do Until date1 = date2
                date1 = date1.AddDays(1)
                ListBox1.Items.Add(date1)
            Loop
        End If


    End Sub

    


Share This

Subscribe

More Tutorials

Popular

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.