9
Contributors
9
Replies
35
Views
6 Years
Discussion Span
Last Post by AMBIgainathan
1
DateTime dt = Convert.ToDateTime(txtDate1.Text); //mm/dd/yyyy
DateTime dt1 = Convert.ToDateTime(txtDate2.Text);//mm/dd/yyyy
TimeSpan ts = dt.Subtract(dt1);
diffDate.Text  = ts.Days.ToString() ;
0

Use this code ,It may help you
DateTime sdate = Convert.ToDateTime(txtFromDate.Value);
DateTime edate = Convert.ToDateTime(txtToDate.Value);
TimeSpan ts = edate - sdate;
int days = ts.Days;

0

Thanks for sharing the information regarding calculating the date difference. It was very useful.

0

use these mththods

DateTime newDate = new DateTime(2000, 5, 1);

System.TimeSpan diff = secondDate.Subtract(firstDate);

String diff2 = (secondDate - firstDate).TotalDays.ToString();

full source C# Date Difference

0

Doubting

Can i use DateTime different = date1 - date2; instead of using TimeSpan data type?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.