C# program to get the date of yesterday using TimeSpan
//C# program to get the date of yesterday using TimeSpan.
using System;
class Demo
{
static void Main()
{
DateTime todayDate = DateTime.Now;
DateTime yesterday;
yesterday = todayDate - new TimeSpan(1, 0, 0, 0);
Console.WriteLine("Yesterday: {0}/{1}/{2}", yesterday.Day, yesterday.Month,yesterday.Year);
}
}
Output
Yesterday: 12/9/2020
Press any key to continue . . .
Table of Contents