DatePart Function
DatePart 函式會傳回日期的指定部分。
DatePart (interval As String, date As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Long
傳回值類型:
The extracted part for the given date.
 interval - A string expression from the following table, specifying the date interval.
  
    | interval (string value) | 說明 | 
  
    | yyyy | 年 | 
  
    | q | 季 | 
  
    | m | 月 | 
  
    | y | 一年的天數 | 
  
    | w | 工作日 | 
  
    | ww | 一年的週數 | 
  
    | d | 日 | 
  
    | h | 時 | 
  
    | n | 分 | 
  
    | s | 秒 | 
 
 date - The date from which the result is calculated.
Date literals allow to specify unambiguous date variables that are independent from the current language. Literals are enclosed between hash signs #. Possible formats are:
    - 
        #yyyy-mm-dd# 
- 
        #mm/dd/yyyy# 
 
 firstdayofweek: An optional parameter that specifies the starting day of a week.
  
    | firstdayofweek value | 說明 | 
  
    | 0 | 使用系統預設值 | 
  
    | 1 | 星期日 (預設值) | 
  
    | 2 | 星期一 | 
  
    | 3 | 星期二 | 
  
    | 4 | 星期三 | 
  
    | 5 | 星期四 | 
  
    | 6 | 星期五 | 
  
    | 7 | 星期六 | 
 firstweekofyear: An optional parameter that specifies the starting week of a year.
  
    | firstweekofyear value | 說明 | 
  
    | 0 | 使用系統預設值 | 
  
    | 1 | 第 1 週是有 1 月 1 日的那一週 (預設值) | 
  
    | 2 | 第 1 週是包含該年之日期 4 天以上的那一週 | 
  
    | 3 | 第 1 週是包含 1 月 1 日的那一週 | 
 
Sub example_datepart
    MsgBox DatePart("ww", #01/02/2005#) ' displays 2 because weeks start on Sunday
    MsgBox DatePart("ww", #12/31/2005#) ' displays 53
    MsgBox DatePart(date:=#2005-12-30#, interval:="q") ' displays 4
End Sub