tags:

views:

55

answers:

3

i have created VB.net project.In that i have two textbox,and two buttons

  • button1-->submit
  • button2-->Duedate
  • textbox1 contain the current date

My constraints is if i click button2(Duedate) than add 30 days to textbox1 date and assign that value into textbox2. How to achieve this?

I want the result like as folloes

If I give textbox1 = 12/12/2009
than
I click Duedate: textbox2.text =11/1/2010

Is it possible. Thanks in advance.

+1  A: 

Your button text should be something like:

    If IsDate(TextBox1.Text) Then
        Dim newdate As Date = CDate(TextBox1.Text)
        newdate = newdate.AddDays(30)
        Dim myDateFormat As String = "dd/MM/yyyy" //or whatever
        DueDateTExtbox2.Text = newdate.ToString(myDateFormat)
    End If
hawbsl
I triedi gave textbox1.text=27/12/2009But it shows error the following lineDim newdate As Date = CDate(TextBox1.Text)Error message:Conversion from String 27/12/2010 to date not valid
+3  A: 

Like so:

Dim d As Date
If DateTime.TryParse(textbox1.Text, d) Then
  textbox2.Text = d.AddDays(30).ToShortDateString()
End If
Dan Story
A: 
        'test data
    Dim dStr As String = "25/12/2009"
    Dim d, d30 As DateTime
    Dim invC As New System.Globalization.CultureInfo("") 'invariant culture
    If DateTime.TryParseExact(dStr, "dd/M/yyyy", _
                              invC, _
                              Globalization.DateTimeStyles.AllowWhiteSpaces _
                              Or Globalization.DateTimeStyles.AssumeLocal, d) Then
        d30 = d.AddDays(30)
    End If
dbasnett