Reu Roo
Reu Roo

Reputation: 141

How to add months to a date

I just want to share the answer to my question. This is the code:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim NextTime As Date = Now
    TextBox1.Text = NextTime.AddDays("set a count here".0) ' for example (100.0)
End Sub

This can be used for due dates or date counter.

Upvotes: 0

Views: 2052

Answers (1)

Leon
Leon

Reputation: 877

Dim newDate As DateTime = DateTime.Parse(Label1.Text).AddMonths(6)

Duedate.text = newDate.ToString

You need to make sure the format is correct though, this can be done with the following bit of code:

Dim pattern As String = "MM-dd-yy" 
Dim parsedDate As Date 

   If DateTime.TryParseExact(Label1.Text, pattern, Nothing, 
                             DateTimeStyles.None, parsedDate) Then
      Console.WriteLine("We're good!)
   Else
      Console.WriteLine("Unable to convert")
   End If                                                          

Upvotes: 2

Related Questions