Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 如何使用format()或vb脚本中的任何方式获取上一个月的名称和年份?_Vbscript - Fatal编程技术网

Vbscript 如何使用format()或vb脚本中的任何方式获取上一个月的名称和年份?

Vbscript 如何使用format()或vb脚本中的任何方式获取上一个月的名称和年份?,vbscript,Vbscript,如何使用format()或vb脚本中任何可能的方式获取上一个月的名称和年份 例如:如果当前月份=2月,我希望输出=2014年1月 如果当前月份=2014年1月,我希望输出=2013年12月 请帮忙。试试这个例子 Dim dateGiven As DateTime = Date.Now dateGiven = dateGiven.AddMonths(-1) MsgBox(dateGiven.ToString("Y")) 如果要删除逗号,请执行以下操作 Dim dateGiven As Date

如何使用format()或vb脚本中任何可能的方式获取上一个月的名称和年份

例如:如果当前月份=2月,我希望输出=2014年1月 如果当前月份=2014年1月,我希望输出=2013年12月

请帮忙。

试试这个例子

Dim dateGiven As DateTime = Date.Now
dateGiven = dateGiven.AddMonths(-1)

MsgBox(dateGiven.ToString("Y"))
如果要删除逗号,请执行以下操作

Dim dateGiven As DateTime = Date.Now
Dim output As String = ""
dateGiven = dateGiven.AddMonths(-1)

output = dateGiven.ToString("Y")

output = output.Replace(",", "")
MsgBox(output)
试试这个例子

Dim dateGiven As DateTime = Date.Now
dateGiven = dateGiven.AddMonths(-1)

MsgBox(dateGiven.ToString("Y"))
如果要删除逗号,请执行以下操作

Dim dateGiven As DateTime = Date.Now
Dim output As String = ""
dateGiven = dateGiven.AddMonths(-1)

output = dateGiven.ToString("Y")

output = output.Replace(",", "")
MsgBox(output)

在VB.Net中,您可以使用.AddMonth(-1):

Dim newDate as DateTime=DateTime.Now.AddMonths(-1)

将.ToString()与格式供应商一起使用,以正确的格式返回:

Console.WriteLine(newDate.ToString(“MMMM-yyyy”))

在VBScript中,可以使用DateAdd函数:

Dim newDate:newDate=DateAdd(“m”、-1,现在)

并使用stringbuilder正确设置其格式


wscript.echo CreateObject(“System.Text.StringBuilder”).AppendFormat(“{0:MMMM yyyy}”,newDate).ToString()

在VB.Net中,您可以使用.AddMonth(-1):

Dim newDate as DateTime=DateTime.Now.AddMonths(-1)

将.ToString()与格式供应商一起使用,以正确的格式返回:

Console.WriteLine(newDate.ToString(“MMMM-yyyy”))

在VBScript中,可以使用DateAdd函数:

Dim newDate:newDate=DateAdd(“m”、-1,现在)

并使用stringbuilder正确设置其格式


wscript.echo CreateObject(“System.Text.StringBuilder”).AppendFormat(“{0:MMMM yyyy}”,newDate).ToString()

前面的所有答案都是针对VB.NET的。如果需要VBScript解决方案,请尝试以下操作:

' Here's how you can get the starting and ending days of the previous month...
dtEnding   = Date - Day(Date)
dtStarting = dtEnding - Day(dtEnding) + 1

' To display the month and year...
MsgBox MonthName(Month(dtEnding)) & " " & Year(dtEnding)

之前的所有答案都是针对VB.NET的。如果需要VBScript解决方案,请尝试以下操作:

' Here's how you can get the starting and ending days of the previous month...
dtEnding   = Date - Day(Date)
dtStarting = dtEnding - Day(dtEnding) + 1

' To display the month and year...
MsgBox MonthName(Month(dtEnding)) & " " & Year(dtEnding)

这是我能找到的最干净的方法。谢谢。这是我能找到的最干净的方式。谢谢