How to get previous month


#1

HI All

 Please help. I have a question. I need to get previous month. but I don't know. 

like current month is Oct . code is ‘DateTime.Now.ToString(“MMM”)’ , but I want to get “Sep”. How to do ?

Thanks.


#2

Hi @guanyan try this - DateTime.Now.AddMonths(-1).ToString(“MMM”)


#3

yeah.get Sep. that is ok. thank a lot.
But I don’t know , why I get 9 using - DateTime.Now.AddMonths(-1).Month.ToString(“MMM”)
why get Sep using - DateTime.Now.AddMonths(-1).ToString(“MMM”)


#4

I am sorry but I am not able to understand you…
for ‘Sep’ - DateTime.Now.AddMonths(-1).ToString(“MMM”)
for Number ‘09’ - DateTime.Now.AddMonths(-1).ToString(“MM”)


#5

DateTime.Now.AddMonths(-1).Month.ToString , I can get 9 . :grin:


#6

Ok, thanks. I got it.


#7

I think the (“M…”) is digit.


#8

Yes you are correct @guanyan (M) =9 , (MM) =09 , (MMM) =Sep