Getting prior month single digit

I am having trouble finding how exactly to write a fairly simple line of code. I want to get the previous month single digit to a string ex. for today would be “2”.

So far I have system.datetime.now.addmonths(-1).tostring(“M”) but it is giving me “February 27”. how can i change this for it to give the single digit of previous month like “2”

DateTime dt = DateTime.Now
intPreviousMonth = dt.Month -1

Please add some valiadtions if month is December and January.

is there no way to get datetime.now to spit out the previous month with just one digit? that way seems overly complicated especially when it comes to january.

@josh.cusack
have a look here
grafik

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.