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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vishal GilbilePosted Mar 26, 2013, 2:48 AM
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 VPosted Mar 26, 2013, 6:18 AM
Satyapriya NayakPosted Mar 26, 2013, 4:50 AM
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 VPosted Mar 26, 2013, 4:37 AM
Vishal GilbilePosted Mar 26, 2013, 4:16 AM
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 VPosted Mar 26, 2013, 2:56 AM