我试图将两个日期作为变体,以便我可以将它们换入和换出每个月运行的 SQL 查询(具有不同的时期)。我试图在 "yyyy-mm-dd"
中获得上个月的 24 日"yyyy-mm-dd"
中的格式和当月 23 日(程序运行时)格式。我有这段代码,但它给了我“错误数量的参数”作为错误,我不明白为什么。
Option Explicit
Sub mDateSet()
Dim fromDateFinal As String
Dim toDate As String
Dim toDateFinal As String
Dim fromDate: fromDate = Format(DateAdd("M", -1, Now), "yyyy-mmmm")
'Format gives 'wrong number of arguments or invalid property assignment error'
'trying to define two dates: the 24th of last month until the 23rd of this month)
'24th of last month
fromDateFinal = fromDate & "24"
Debug.Print fromDateFinal
'23th of this month
toDate = Format(Date, "yyyy-mm")
toDateFinal = toDate & "23"
Debug.Print toDateFinal
End Sub
最佳答案
以下是来自操纵日期和格式掩码的一些字符串日期。
fromDateFinal = format(date-day(date), "yyyy-mm-24") '2018-02-24
toDateFinal = format(date, "yyyy-mm-23") '2018-03-23
关于vba - 试图获得两个日期,上个月的 24 日和本月的 23 日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49049962/