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
SilverLight
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
Calculate the Number of Days, Months & Years with Asp.Net DateTime object
Posted by
Moderator1
on
3/29/2009 1:53:18 AM
3195
Views
The Number of Days, Months and Years can be calculated in Asp.Net with the help of TimeSpan class. By using the Subtract Method of TimeSpan class, we can easily find out the interval between two DateTime objects. Follow the sample code below,
DateTime date1 = Convert.ToDateTime("2008/01/01");
DateTime date2 = Convert.ToDateTime("2008/12/31");
TimeSpan timespan = date2.Subtract(date1);
int NoofDays = timespan.Days;
double TotMonth = Math.Floor(NoofDays / 30.0);
double TotYear = Math.Floor(NoofDays / 365.0);
Response.Write("No. of Days : " + NoofDays.ToString());
Response.Write("No. of Months : " + TotMonth.ToString());
Response.Write("No. of Years : " + TotYear.ToString());
Post New Tips/Tricks
View all Tips/Tricks
Featured Resources:
Sexy Web Design - Free 71 Page Preview!
An easy-to-follow guide that reveals the secrets of how to build your own breathtaking web interfaces from scratch.
FierceDeveloper
Is a free weekly email newsletter for the wireless developer community.
100% Free Subscription until Stock lost.
View complete list.
Sponsored by
Home
About us
Contact Us
Links
Advertise
Privacy Policy
Copyright ©
2012
. www.AspdotnetCodes.com. All rights reserved.