Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 How To Find Number of Days between two Dates in C# Asp.Net?
Posted by Moderator1 on  1/30/2009 8:03:38 AM 24124 Views
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"));

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's Days property we can add 1 to get the exact number of days.

Post New Tips/Tricks View all Tips/Tricks

Featured Resources:
Easing the Migration to Microsoft SQL Server 2005
There are many business and technological reasons for making the move to SQL Server 2005 and SQL Server 2005 Enterprise Edition. In tandem with 64-bit computing platforms, SQL Server 2005 can boost performance by 30% in certain instances, deliver a better database management structure and bolster infrastructure security.
The ASP.NET 2.0 Anthology: 101 Essential Tips, Tricks & Hacks - Free 156 Page Preview
Learn the most practical features and best approaches for ASP.NET.
100% Free Subscription until Stock lost.View complete list.
Sponsored by