Register
|
Articles
|
Questions
|
Projects
|
Asp.Net Tips
|
Free Magazines
|
Tutorials
|
Search
|
Write to us
|
Login
Search
Articles
Asp.Net 2.0
AJAX
ADO.Net
C#
Javascript
Books
Asp.Net 2.0
AJAX
ADO.NET
C#
JavaScript
MS SQL Server
VB.NET
XML
Web Service
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
5755
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:
Simply JavaScript - Free 150 Page Preview!
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Many .NET teams are underperforming, is yours?
Explore how you can turn your .NET developer training program from a commonly ignored budget line-item into a strategic weapon in today's competitive software environment.
100% Free Subscription until Stock lost.
View complete list.
Sponsored by
Home
About us
Contact Us
Links
Advertise
Privacy Policy
Copyright ©
2010
. www.AspdotnetCodes.com. All rights reserved.