2016-03-30 26 views
-6

先週の最初と最後の日に誰かがコードを提供できますか?前週の最初と最後の日を取得する

ありがとうございます。

+4

[いくつかの一般的な日付ルーチン](http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines /)を参照してください。 –

+0

あなたの週の最初の日は何ですか?それは文化に依存します。 –

答えて

1

あなたは、これらの機能を使用することができます。

Public Function DateWeekFirst(_ 
    ByVal datDate As Date, _ 
    Optional ByVal lngFirstDayOfWeek As VbDayOfWeek = vbUseSystemDayOfWeek) _ 
    As Date 

' Returns the first date of the week of datDate. 
' lngFirstDayOfWeek defines the first weekday of the week. 
' 2000-09-07. Cactus Data ApS. 
' 2003-05-01. System settings used as default. 
' 2012-10-44. Data type of lngFirstDayOfWeek changed to VbDayOfWeek. 

    DateWeekFirst = DateAdd("d", vbSunday - Weekday(datDate, lngFirstDayOfWeek), datDate) 

End Function 

Public Function DateWeekLast(_ 
    ByVal datDate As Date, _ 
    Optional ByVal lngFirstDayOfWeek As Long = vbUseSystemDayOfWeek) _ 
    As Date 

' Returns the last date of the week of datDate. 
' lngFirstDayOfWeek defines the first weekday of the week. 
' 2000-09-07. Cactus Data ApS. 
' 2003-05-01. System settings used as default. 
' 2012-10-44. Data type of lngFirstDayOfWeek changed to VbDayOfWeek. 

    DateWeekLast = DateAdd("d", vbSaturday - Weekday(datDate, lngFirstDayOfWeek), datDate) 

End Function 

そして、例えば:

FirstDatePreviousWeek = DateWeekFirst(DateAdd("ww", -1, Date)) 
関連する問題