Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find previous month in vb6 or in vba?

Tags:

vba

vb6

i written a code in vb for finding the last month. but i didn't get the output which i am expecting. here is my code:

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

but i want output in 2 digit like if last month is Jan then output should be 01 not only 1

please help me out.

like image 310
Pratik Gujarathi Avatar asked Dec 22 '22 01:12

Pratik Gujarathi


1 Answers

Use the DateAdd function. More specifically:

date d = DateAdd("m", -1, Now)
a = Format(d, "mm")
like image 63
Philip Sheard Avatar answered Jan 02 '23 13:01

Philip Sheard