Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i select date from textbox1,textbox2 displays textbox1 value + 20 years
Posted

Try this
date time dt=(DateTime)textbox1.text;
textbox2.text=dt.AddYears(20);
 
Share this answer
 
Comments
Simon_Whale 26-May-11 5:55am    
VB Version

dim d as date = ctype(textbox1.text,date)
textbox2.text = d.addyears(20)
Sergey Alexandrovich Kryukov 26-May-11 15:33pm    
Sure, a 5.
--SA
Did you try? based on the question, it looks like you did not even gave it a shot.

Few hints:
1. Date entered in textbox1 has to be in proper format and a valid date.
2. It would be a string when entered, take it and convert it into a datetime object
3. Create another datetime object and use AddYear() method of the datetimeobject to add 20 years to first one
4. Use one of the various convert to specific string format method of the datetimeobject and assign it to the textbox2.

Done. Now, try!
 
Share this answer
 
Use this concept.
textbox2.Text = CDate(textbox1.Text).AddYears(20)
 
Share this answer
 
MSDN Dateadd function[^]

VB
Dim d As Date
d = DateAdd(DateInterval.Year, 20, CType(TextBox1.Text, Date))


A quick google would of given you a whole list of examples too Google: vb.net hot to add years to a date[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900