DatePart 函数
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 天以上天数的第 1 周 | 
  
    | 3 | 第 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