To Know the Number of Days between two dates

No.of Views1115
Bookmarked0 times
Downloads 
Votes0
By  Troy   On  15 Feb 2010 23:02:08
Tag : CSharp , How to
To Know the Number of Days between two dates
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction


Here we have to discuss To know the number of Days Between two dates.

Technologies:

.Net 2.0

Language:

C# and VB.NET, Asp.net


Prerequisite

.NET Framework 2.0


Visual Studio 2005


Implementation

{codecitation class="brush: csharp; gutter: true;" width="650px"}

int i = firstDate.Subtract(secondDate).Days;

{/codecitation}


Code-Behind

{codecitation class="brush: csharp; gutter: true;" width="650px"}

protected void Page_Load(object sender, EventArgs e)
{
DateTime startTime = new DateTime(2009, 1, 7);
DateTime endTime = new DateTime(2009, 8, 7);

TimeSpan span = endTime.Subtract(startTime);
Response.Write("Time Difference (seconds): " + span.Seconds + "
");
Response.Write("Time Difference (minutes): " + span.Minutes + "
");
Response.Write("Time Difference (hours): " + span.Hours + "
");
Response.Write("Time Difference (days): " + span.Days);
}

{/codecitation}

Thank you

Venkat

 
Sign Up to vote for this article
 
About Author
 
Troy
Occupation-Not Provided
Company-Not Provided
Member Type-Junior
Location-Not Provided
Joined date-10 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top