Pratik Gujarathi
Pratik Gujarathi

Reputation: 768

How to find previous month in vb6 or in vba?

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.

Upvotes: 4

Views: 11761

Answers (1)

Philip Sheard
Philip Sheard

Reputation: 5815

Use the DateAdd function. More specifically:

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

Upvotes: 11

Related Questions