• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 937
  • Last Modified:

How to increment the date?

Hello Guys! I'm trying to to display the next days's date whenever the user clicks the button.Not quite sure how can i do it in vb.net.
Basically the date should be incremented by one everytime we click on the submit button.

For eg: 24/5   click
            25/5   click
            26/5   click
I'm attaching the code that i've used to display tomorrow's date. Thanks in advance.
Dim Dt As DateTime = DateTime.Now()
        Dim dtTomorrow As DateTime
        dtTomorrow = Dt.AddDays(1)
        txtempattendence.Text = dtTomorrow.ToShortDateString

Open in new window

1 Solution
preethamonlineAuthor Commented:
I got the solution guys!

 Dim dt As DateTime
        If ViewState("currentDate") Is Nothing Then
            If Not DateTime.TryParse(txtempattendence.Text, dt) Then
                Throw New ArgumentException("This is not a valid date")
            End If
            dt = CType(ViewState("currentDate"), DateTime)
        End If

        Dim newDate As DateTime
        newDate = dt.AddDays(1)
        ViewState("currentDate") = newDate
        txtempattendence.Text = newDate.ToShortDateString
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now