Follow by Email

Friday, September 13, 2013

calculating days,months,years difference between two dates in asp.net,C# | calculating date difference using timespan to calculate days,months,years

hi in this post i will show how to calculate days,months and years between two date in asp.net,c#(code-behind):

Below is the code for this:

public void calcDayMonthYear()
{

        DateTime dayStart;
        DateTime dateEnd;

        dayStart = Convert.ToDateTime(frmdate.Text);
        dateEnd = Convert.ToDateTime(todate.Text);
        TimeSpan ts = dateEnd - dayStart;

        double Years = Convert.ToDouble(ts.TotalDays) / 365;
        double Months = Years * 12;
        double Days = Convert.ToDouble(ts.TotalDays); 


}