How to get previous month

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.

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

4 Likes

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”)

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”)

1 Like

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

Ok, thanks. I got it.

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

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

2 Likes