DateDiff Function

Returns the number of date or time intervals between two given date values.

Syntax:


DateDiff (interval As String, date1 As Date, date2 As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Double

傳回值類型

數字。

Parameters:

interval - A string expression from the following table, specifying the date or time interval.

interval (string value)

說明

yyyy

q

m

y

一年的天數

w

工作日

ww

一年的週數

d

h

n

s


date1, date2 - The two date values to be compared.

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_datediff
    MsgBox DateDiff("d", #1/1/2005#, #2005-12-31#)
End Sub

Please support us!