user246160
user246160

Reputation: 1407

DATE concept in VB.NET

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

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.

Upvotes: 0

Views: 564

Answers (3)

dbasnett
dbasnett

Reputation: 11773

        '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

Upvotes: 0

Dan Story
Dan Story

Reputation: 10155

Like so:

Dim d As Date
If DateTime.TryParse(textbox1.Text, d) Then
  textbox2.Text = d.AddDays(30).ToShortDateString()
End If

Upvotes: 3

hawbsl
hawbsl

Reputation: 16053

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

Upvotes: 1

Related Questions