如何在 vb6 或 vba 中查找上个月?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9496394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 15:23:36 来源:igfitidea点击:
How to find previous month in vb6 or in vba?
提问by Pratik Gujarathi
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:
我在 vb 中编写了一个代码来查找上个月。但我没有得到我期望的输出。这是我的代码:
a=Format$(Now, "mm")-1
but i want output in 2 digit like if last month is Janthen output should be 01not only 1
但我想要 2 位数的输出,就像上个月是1 月一样,那么输出应该是01而不仅仅是1
please help me out.
请帮帮我。
回答by Philip Sheard
Use the DateAdd function. More specifically:
使用 DateAdd 函数。进一步来说:
date d = DateAdd("m", -1, Now)
a = Format(d, "mm")