How to find the previous month in vb6 or in vba?

I wrote code in vb to search for the last month. but I did not get the result that I expect. here is my code:

a=Format$(Now, "mm")-1 

but I want a 2-digit output, for example, if last month was Yang , then the output should be 01 not only 1

please help me.

+4
source share
1 answer

Use the DateAdd function. More specific:

 date d = DateAdd("m", -1, Now) a = Format(d, "mm") 
+11
source

Source: https://habr.com/ru/post/1398976/


All Articles