C# program to display the previous day


To display the previous day, use the AddDays() method and a value -1 to get the previous day.

Firstly, use the following to get the current day −

DateTime.Today

Now, add -1 to the AddDays() method to get the previous day −

DateTime.Today.AddDays(-1)

The following is the code −

Example

 Live Demo

using System;
using System.Collections.Generic;
using System.Linq;
public class Demo {
   public static void Main() {
      Console.WriteLine("Today = {0}", DateTime.Today);
      Console.WriteLine("Previous Day = {0}", DateTime.Today.AddDays(-1));
   }
}

Output

Today = 9/4/2018 12:00:00 AM
Previous Day = 9/3/2018 12:00:00 AM

Updated on: 22-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements