DATE concept in VB.NET
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 t开发者_高级运维he 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.
Like so:
Dim d As Date
If DateTime.TryParse(textbox1.Text, d) Then
  textbox2.Text = d.AddDays(30).ToShortDateString()
End If
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
        '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
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论