6 March 2014

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

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); 
}

No comments:

Post a Comment