Using Date Formatting


#1

Hello,
I am having issues with using date formatting and I would like to get more in depth information on this.

I need the Month to appear as “04” for April, instead of “4”.
If I understood right from other posts, then I could use “(date.Today.Month-1).ToString(“MM”)”.
However that just returns “MM” for me. while “(date.Today.Month-1).ToString” returns 4.
Can you please help with this ?


#2

Hi,

date.Month -1 returns an integer so the date string format is not recognized here. What I would do is date.AddMonths(-1).ToString(“MM”)

BR,
Topi


#3

This way works:
now.Date.AddMonths(-1).ToString(“MM”)