This document shows how to calculate future and past dates and times in C# by adding or subtracting days and minutes from the current date and time using DateTime methods like AddDays and AddMinutes, and outputting the results in custom formats.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
23 views
C# DateTime Function
This document shows how to calculate future and past dates and times in C# by adding or subtracting days and minutes from the current date and time using DateTime methods like AddDays and AddMinutes, and outputting the results in custom formats.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
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 ");
Introduction to Elementary Computational Modeling Essential Concepts Principles and Problem Solving 1st Edition Jose Garrido (Author) - Download the ebook now to start reading without waiting