Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

Calculating Date and time Functions in c#


string strDate;

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

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

// Calculating the time after 15 minute (adding minutes to the current
time.)
// Format : 09 / 08 / 06, 12 : 60
DateTime later = DateTime.Now.AddMinutes( 15 );
strDate = later.ToString("dd / MM / yy, hh : mm ");


// Calculating the time after 1 hour (adding minutes to the current
time.)
// Format : 09 / 08 / 06, 12 : 60
DateTime later = DateTime.Now.AddMinutes( 60 );
strDate = later.ToString("dd / MM / yy, hh : mm ");


// Calculating the time before 1 hour (adding minutes to the current
time.)
// Format : 09 / 08 / 06, 12 : 60
DateTime later = DateTime.Now.AddMinutes( -60 );
strDate = later.ToString("dd / MM / yy, hh : mm ");



Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy

Website Design & Internet Marketing by Shivam