Working With Date in C# Example:
Example Code:
We can use DateTime Class in C# to work with date and time. From that we can get today's date. If we want yesterday's date we can add -1 to current date. If we want tomorrow's date we can simply add 1 to the current date. The following example illustrates how to work with date and time in c#.
Example Code:
class DateAndTimeExample
{
static void Main(string[] args)
{
/*----------Working With Date--------------------*/
DateTime value = new DateTime(2012,2, 25);
Console.WriteLine("Date With Our Values:"+value); //It will print date with our values
Console.WriteLine("Today's Date:" + DateTime.Today);
Console.WriteLine("Tomorrow Date:" + DateTime.Today.AddDays(1));
Console.WriteLine("Yesterday Date:" + DateTime.Today.AddDays(-1));
}
}
Output: