Pages

Monday, February 25, 2013

How to find the difference between two dates using TimeSpan

protected void Page_Load(object sender, EventArgs e)
{
“place to coding in button”
DateTime dFrom;
DateTime dTo;
string sDateFrom = "9/9/2007";
string sDateTo = "1/10/2008";
if (DateTime.TryParse(sDateFrom, out dFrom) && DateTime.TryParse(sDateTo, out dTo))
{
TimeSpan TS = dTo - dFrom;
int daysDiff = TS.Days;
Response.Write(daysDiff.ToString());
//textbox1.text=daysDiff.ToString();
}

No comments:

Post a Comment