DATE
MY QUESTION IS MY TODAY DATE IS TODAY AND WHEN I INSERT 2YEAR PERIOD.THEN SECOND DATE PICKER SET AFTER 2 YEAR DATE MONTH AND YEAR.(DESKTOP APPLICATION)
5 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Akkiraju IvaturiRank #474 · 5.2K pointsPosted Sep 7, 2012, 8:50 PM EDT
ComboBox1 has values of number of years.
For dates, use DateTime.Now.AddDays(14)
For Months, use DateTime.Now.AddMonths(14)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace DateProject { public partial class Form1 : Form { public Form1() { InitializeComponent(); } void ChangeDate() { DateTime dateTime = dateTimePicker1.Value; int count = 0; if (comboBox1.SelectedItem != null) { count = Convert.ToInt32(comboBox1.SelectedItem.ToString()); } DateTime addYears = dateTime.AddYears(count); dateTimePicker2.Value = addYears; } private void Form1_Load(object sender, EventArgs e) { comboBox1.Items.Insert(0,"1"); comboBox1.Items.Insert(1, "2"); comboBox1.Items.Insert(2, "3"); ChangeDate(); dateTimePicker1.ValueChanged += new EventHandler(dateTimePicker1_ValueChanged); comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); } void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { ChangeDate(); } void dateTimePicker1_ValueChanged(object sender, EventArgs e) { ChangeDate(); } } } Let me know if you have any questions.Akkiraju IvaturiRank #474 · 5.2K pointsPosted Sep 7, 2012, 8:03 PM EDT
vikas kanani110 pointsPosted Sep 7, 2012, 8:05 PM EDT
vikas kanani110 pointsPosted Sep 7, 2012, 10:19 PM EDT
Akkiraju IvaturiRank #474 · 5.2K pointsPosted Sep 8, 2012, 12:17 PM EDT
using System;