AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
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 20169 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"));
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's Days property we can add 1 to get the exact number of days.


Post New Tips/Tricks View all Tips/Tricks

Featured Resources:
Programmers Heaven C# School Book - Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Oracle Magazine
Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.
100% Free Subscription until Stock lost.View complete list.
Sponsored by