DatePart Function

DatePart 函式會傳回日期的指定部分。

Syntax:


DatePart (interval As String, date As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Long

傳回值類型

The extracted part for the given date.

Parameters:

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:

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 日的那一週


Example:


Sub example_datepart
    MsgBox DatePart("ww", #12/31/2005#)
    MsgBox DatePart(date:=#1999-12-30#, interval:="q")
End Sub

Please support us!