简体   繁体   English

想要从当前日期获取以前的日期

[英]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.

相关问题 获取当前日期和上一个日期之间的差异 - Get the difference between current date and a previous date 如何从Java中的特定日期获取前7个日期?我正在从当前日期获取7个日期,但我想从特定日期获取 - How to get previous 7 dates from a particular date in java?I am getting 7 dates from present date, but I want from particular date 从当前日期中减去否时如何获取上一个日期。 在PHP中的日子 - How To get previous date when subtracted from current date with no. of days in php 使用日期从-日期到时从当前日期获取预订 - Get Bookings from current date when using Date from - Date To 尝试从 SQL 中的当前日期获取上个月的第一个月和最后一个月时出错 - Error while trying to get first and last of previous month from current date in SQL 如何通过单击左箭头右获取所选日期或当前日期的下一个和上一个日期 - How to get next and previous date of selected date or current date by clicking arrow left Right 查找当前日期是否与上一个日期相同 - Find whether current date is same as previous date JavaScript-如何获取当前日期并存储以前的日期以用于列表中? - JavaScript - How to get current date, and store previous dates, for use in a list? 如何获取当前日期的前4个星期日 - how to get the previous 4 sunday's of the current date javascript 如何只获取laravel中的当前日期和以前的日期? - How to get only the current date and the previous dates in laravel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM