DatePart Function
Hàm DatePart trả về một phần đã ghi rõ của một ngày tháng.
DatePart (interval As String, date As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Long
GIá trị trả về:
The extracted part for the given date.
 interval - A string expression from the following table, specifying the date interval.
  
    | interval (string value) | Giải thích | 
  
    | yyyy | Năm | 
  
    | q | Quý | 
  
    | m | Tháng | 
  
    | y | Ngày của năm | 
  
    | w | Hôm của tuần | 
  
    | ww | Tuần của năm | 
  
    | d | Ngày | 
  
    | h | Giờ | 
  
    | n | Phút | 
  
    | s | Giây | 
 
 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 | Giải thích | 
  
    | 0 | Dùng giá trị mặc định của hệ thống | 
  
    | 1 | Chủ Nhật (mặc định) | 
  
    | 2 | Thứ Hai | 
  
    | 3 | Thứ Ba | 
  
    | 4 | Thứ Tư | 
  
    | 5 | Thứ Năm | 
  
    | 6 | Thứ Sáu | 
  
    | 7 | Thứ Bảy | 
 firstweekofyear: An optional parameter that specifies the starting week of a year.
  
    | firstweekofyear value | Giải thích | 
  
    | 0 | Dùng giá trị mặc định của hệ thống | 
  
    | 1 | Tuần 1 là tuần chứa ngày 1, tháng 1 (mặc định) | 
  
    | 2 | Tuần 1 là tuần thứ nhất chứa ít nhất bốn ngày của năm đó. | 
  
    | 3 | Tuần 1 là tuần thứ nhất chứa chỉ những ngày của năm mới. | 
 
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