To calculate the number of days between two dates in Asp.Net using C#, use the below piece of code.
TimeSpan timespan = Convert.ToDateTime("2009-12-31").Subtract(Convert.ToDateTime("2009-01-01"));
Response.Write(timespan.Days+1);
Here we use Subtract method to find the difference between two dates. Usually the Subtract method return a value that is one less than the correct value. So to the Timespan object Days property we can add 1 to get the exact number of days.
How To Find Number of Days between two Dates in C# Asp.Net?
Posted by
Rajesh Rolen
at
Thursday, September 10, 2009
Labels: ASP.NET , ASP.NET Interview Questions , Interview Questions
0 comments:
Post a Comment