Date picker selection change
I have two Datepicker named datepicker1 and datepicker2 .I have a textbox also.datepicker1 shows the current date and datepicker2 shows a date of six monthes later from now.I want to show the difference in monthes in the textbox when i put the date in the datepicker2.How can i implement this on selection change event using the datepicker2.plz help me.Thanks in advance.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Sanjeeb LenkaRank #301 · 8.3K reputationPosted Feb 9, 2014, 9:17 PM EST
try like this: it may help you
private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
DateTime dt = this.dateTimePicker1.Value.Date;//1st date
DateTime dt2 = this.dateTimePicker2.Value.Date;// selected date
int months = (dt2.Year - dt.Year) * 12 + dt2.Month - dt.Month;
textBox1.Text = months.ToString();
}
Ronok Bhowmik34 reputationPosted Feb 9, 2014, 10:45 PM EST