【VB】取得本週日期區間
Dim week As Integer
Dim first_day As Date
Dim dStartDate As Date = Now '可以設定目前日期
first_day = DateSerial(Year(dStartDate), 1, 1)
'本週定義指 週日(第一天)到週六(最後一天)的日期區間
week = DatePart("ww", dStartDate) '取得今天是屬於今年的第幾週
For i As Integer = 1 To 7
dStartDate = DateAdd("d", 7 * week - 7, DateAdd("d", (i - DatePart("w", first_day)), first_day))
MsgBox(dStartDate)
Next
Ex: 今天是 2011/5/25 則 本週區間依序為:
2011/5/22, 2011/5/23, 2011/5/24, 2011/5/25, 2011/5/26, 2011/5/27, 2011/5/28
留言
張貼留言