[英]Want to get previous date from current date
i have problem finding solution on getting previous date from current's date. 我在从当前日期获取以前的日期时找不到解决方案。 but i only want the months to change.
但我只想改变几个月。 for example, now is August, i want the output to display 3 months ago = May.
例如,现在是8月,我希望输出显示3个月前= 5月。 Heres my code that i wrote
这是我编写的代码
givenDate= "14-August-15"
DD = Day (givenDate)
'MsgBox DD
MM = Month (givenDate)
'MsgBox MM
YY = Year (givenDate)
'MsgBox YY
SysDate = DD&"/"&MM&"/"&YY
MsgBox Month(DateAdd("m", -3, "14-August-2015"))
'MsgBox(FormatDateTime(SysDate,1))
If you just need to display the name of the month that was 3 months ago, combine DateAdd()
, Month()
, and MonthName()
. 如果只需要显示3个月前的月份的名称,请结合使用
DateAdd()
, Month()
和MonthName()
。 For example: 例如:
Dim dt1, dt2
dt1 = Date() ' Use today's date, for example
dt2 = DateAdd("m", -3, dt1) ' Subtract 3 months
WScript.Echo MonthName(Month(dt2)) ' Display the name of the month
Month()
returns the month number ( 1 - 12
). Month()
返回月份数( 1 - 12
)。 MonthName()
takes that number and returns the name of the month ( "January" - "December"
). MonthName()
该数字并返回月份的名称( "January" - "December"
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.