C# Program to Get the Date of Yesterday Using Timespan

You are currently viewing C# Program to Get the Date of Yesterday Using Timespan

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 . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply