
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements