
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
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
- Related Articles
- Java Program to display previous day from GregorianCalender
- Java Program to display previous year from GregorianCalendar
- Java Program to display previous month from GregorianCalendar
- C# program to display the next day
- How to get the previous day with MySQL CURDATE()?
- How to get last day of the previous month in MySQL?
- Get all MySQL records from the previous day (yesterday)?
- How to get the first day of the previous month in MySQL?
- Java Program to display date with day name in short format
- Java Program to get display name for Day of Week in different locale
- How to display first day and last day of the month from date records in MySQL?
- Java Program to get the previous node from a JTree
- Java program to get the previous sibling from a JTree
- Java Program to get the previous leaf from a JTree
- Golang Program to round up the next previous power of 2.

Advertisements