我知道這可能是一個簡單的問題,但我無法弄清楚這一點。當運行VBA的調試器時,第11行的第三個參數按預期顯示爲「9/13/2016」,但由於某些原因,start_d是「06/09/2016」?DateAdd返回值不正確
我曾嘗試將start_d設置爲字符串和Date對象,兩者都產生相同的結果。我想要的只是start_d在當前日期前7天。
Sub addData(lastRow As Integer, lab() As String, c() As String, IP() As String, usage() As String, fName As String)
Dim reportWeek As Integer
Dim numWeeks As Integer
Dim monthWeek As Integer
Dim start_d As Date ' As String UPDATED
Dim thisYear As String
Dim thisMonth As String
Dim thisDay As String
' the reports run every monday
start_d = DateAdd("d", -7, Date)
'start_d = Format(start_d, "dd/mm/yyyy") UPDATED
thisYear = year(start_d) 'year(CDate(start_d)) UPDATED
thisMonth = month(start_d) 'month(CDate(start_d)) UPDATED
thisDay = day(start_d) 'day(CDate(start_d)) UPDATED
reportWeek = weekNum
monthWeek = getWeekOfMonth(CDate(start_d))
numWeeks = weekCount(thisYear, thisMonth)
Debug.Print reportWeek & monthWeek & numWeeks & thisYear & thisMonth & thisDay
End Sub
將系統日期格式更改爲dd-mm-yyyy。 – HA560
在我的筆記本電腦上沒有dd-mm-yyyy選項,所以我使用了dd-MM-yy。 start_d仍然不正確:「06-09-2016」。爲什麼它甚至不是系統日期的格式......? –
@ HA560我可以自定義它到您提出的日期,它仍然提出「06-09-2016」 –