Hi!!
How to calculate date based on giving years as input in textbox ??
eg: textbox1 value is : 26/03/2013
textbox2: 3(years)
textbox3: output(26/03/2016)
thanks in advance!!!
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 25, 2013, 10:48 PM EDT
All you need to do is add the no of specified year from textbox2 to textbox1 date.Following code may help you to do the same.
DateTime dt1=Convert.ToDateTime(textbox1.Text);
int noofYear = Convert.ToInt32(str2);
textBox3.Text = dt1.AddYears(noofYear).ToShortDateString();
Hope that Solves your problem.
With Regards,
Vishal Gilbile
AbhiPriya M V63 reputationPosted Mar 25, 2013, 10:56 PM EDT
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 26, 2013, 12:16 AM EDT
First tell the me the scenario where you are implementing this thing. If you talk from normal point of view wherever you want to implement it you can implement it for eg. if you want to add year on button click event you'll write the code on Button_Click event of button control.
With Regards,
Vishal Gilbile.
AbhiPriya M V63 reputationPosted Mar 26, 2013, 12:37 AM EDT
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 26, 2013, 12:50 AM EDT
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DateTime dt1 = DateTime.Parse(Convert.ToDateTime(textBox1.Text).ToShortDateString());//input as 2013,3,26(yyyy,mm,dd)
int noofYear = Convert.ToInt32(textBox2.Text);
textBox3.Text = dt1.AddYears(noofYear).ToString("dd/MM/yyyy");
}
}
}
AbhiPriya M V63 reputationPosted Mar 26, 2013, 2:18 AM EDT