C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

How to Subtract Dates


Posted Date: 22 May 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: Siva PrasadMember Level: Gold    
Rating: 1 out of 5Points: 3



The following code example shows Subtraction of dates.



DateTime dateTimeOne = Convert.ToDateTime ( "3/28/2008 12:05:45 pm" );

DateTime dateTimeTwo = Convert.ToDateTime ( "5/22/2008 12:21:20 pm" );

TimeSpan timeSpan = dateTimeTwo - dateTimeOne;


For C#

MessageBox.Show ( "Days = " + timeSpan.Days + ", " + timeSpan.TotalHours + " : " + timeSpan.TotalMinutes );


For ASP.NET


Response.Write ( "Days = " + timeSpan.Days + ", " + timeSpan.TotalHours + " : " + timeSpan.TotalMinutes );

IN the above code i had taken two datetime classes , created instances for both of them and i subtracted both of them which returns timespan.

Timespan class contains properties , those properties will do the rest of the thing




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Date  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Stored Files are Retrived using this code
Previous Resource: Excel Sheet and XML Operations
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use