想要从当前日期获取以前的日期 [英] Want to get previous date from current date
本文介绍了想要从当前日期获取以前的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在从当前日期获取以前的日期方面找不到解决方案。但我只想改变几个月。例如,现在是8月,我希望输出显示3个月前= 5月。
这是我编写的代码
givenDate = 15年8月14日
DD =天(给定日期)
'MsgBox DD
MM =月(给定日期)
'MsgBox MM
YY =年(给定日期)
'MsgBox YY
SysDate = DD& /& MM& /& YY
MsgBox Month(DateAdd( m,-3 , 2015年8月14日))
'MsgBox(FormatDateTime(SysDate,1))
解决方案
如果您只需要显示3个月前的月份名称,则将 DateAdd()
, Month()
和 MonthName()
。例如:
Dim dt1,dt2
dt1 = Date()'使用今天的日期,例如
dt2 = DateAdd( m,-3,dt1)'减去3个月
WScript.Echo MonthName(Month(dt2))'显示月份的名称
Month()
返回月份号( 1 -12
)。 MonthName()
获取该数字并返回月份名称(一月-十二月
)。 / p>
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. 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()
. 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
). MonthName()
takes that number and returns the name of the month ("January" - "December"
).
这篇关于想要从当前日期获取以前的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文