C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Adding and subtracting date and time


Posted Date: 18 Mar 2004    Resource Type: Articles    Category: .NET Framework

Posted By: Tony John       Member Level: Gold
Rating:     Points: 10



You can use the AddDays() method to add or subtract days from the datetime object. To subtract days, just add a negative number.

Similarly, you can use methods like AddHours(), AddMinutes() etc. See the following example :


string formattedDate;

// Calculating the yesterday's date (substracting days from current
date.)
DateTime yesterday = DateTime.Today.AddDays( -1 );
formattedDate = yesterday.ToString("dd / MM / yy");

// Calculating the tomorrow's date (adding days to the current date.)
DateTime tomorrow = DateTime.Today.AddDays( 1 );
formattedDate = tomorrow.ToString("dd / MM / yy");

// Calculating the time after 5 minute (adding minutes to the current
time.)
// Format : 07 / 03 / 04, 10 : 30
DateTime later = DateTime.Now.AddMinutes( 5 );
formattedDate = later.ToString("dd / MM / yy, hh : mm ");




Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

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: Formatting Date and Time using the DateTime object
Previous Resource: Handling Events in .Net - Part I
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use