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 ");
|
No responses found. Be the first to respond and make money from revenue sharing program.
|