使用VBScript格式化前一天格式的日期yyyymmdd [英] Format the date of the previous day format yyyymmdd with VBScript
本文介绍了使用VBScript格式化前一天格式的日期yyyymmdd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 VBScript 以此格式格式化前一天的日期:
I need format the date of the previous day in this format, with VBScript :
yyyymmdd
yyyymmdd
我已经尝试过此解决方案:
And I have tried this solution :
NewData = Right(Year(DateSerial(Year(Date()),Month(Date()),1)),4) &_
Right(String(2, "0") &_
Month(DateSerial(Year(Date()),Month(Date()),1)), 2) &_
Right(String(2, "0") &_
Day(DateAdd("d",-1, Now())), 2)
但是没有得到:
20190630
20190630
我有:
20190730
20190730
你能帮我吗?
在此先感谢您的帮助.
推荐答案
您应该首先将昨天存储在变量中,然后在此日期进行格式化.
You should first store yesterday in a variable and then do your formatting magic on this date.
dim yesterday
yesterday = DateAdd("d",-1, Now())
NewData = Right(Year(DateSerial(Year(yesterday),Month(yesterday),1)),4) _
& Right(String(2, "0") _
& Month(DateSerial(Year(yesterday),Month(yesterday),1)), 2) _
& Right(String(2, "0") & Day(yesterday), 2)
我强烈怀疑还有更直接的方法来获取格式为YYYYMMDD的日期.
I strongly suspect there are more straightforward ways to get a date in format YYYYMMDD however.
这篇关于使用VBScript格式化前一天格式的日期yyyymmdd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文