Home > Forum > C# > How can I get previous month and year in C#

How can I get previous month and year in C#

by Thamil   on Aug 18, 2014   Category: C#  |  Views: 4410    |  Points: 5   |  Gold 
  Reply
I need to get previous month and year in c#.

Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :How can I get previous month and year in C#   
by Thamil
on Aug 18 2014 11:33PM
Points : 10
Gold 
Solution:

By using DateTime.AddMonths we can able to achieve this. Find the below code
DateTime dt = DateTime.Now;
dt = dt.AddMonths(-1);
int month = dt.Month;
int Year = dt.Year;

Recent Post

Latest Posts