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

Year

q

Quarter

m

Month

y

Day of year

w

Weekday

ww

Week of year

d

Day

h

Hour

n

Minute

s

Second


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

Use system default value

1

แƒ™แƒ•แƒ˜แƒ แƒ (แƒกแƒแƒฌแƒงแƒ˜แƒกแƒ˜)

2

แƒแƒ แƒจแƒแƒ‘แƒแƒ—แƒ˜

3

แƒกแƒแƒ›แƒจแƒแƒ‘แƒแƒ—แƒ˜

4

แƒแƒ—แƒฎแƒจแƒแƒ‘แƒแƒ—แƒ˜

5

แƒฎแƒฃแƒ—แƒจแƒแƒ‘แƒแƒ—แƒ˜

6

แƒžแƒแƒ แƒแƒกแƒ™แƒ”แƒ•แƒ˜

7

แƒจแƒแƒ‘แƒแƒ—แƒ˜


firstweekofyear: An optional parameter that specifies the starting week of a year.

firstweekofyear value

แƒแƒฎแƒกแƒœแƒ

0

Use system default value

1

แƒ™แƒ•แƒ˜แƒ แƒ 1 แƒแƒ แƒ˜แƒก แƒ™แƒ•แƒ˜แƒ แƒ แƒ˜แƒแƒœแƒ•แƒ แƒ˜แƒ—, แƒžแƒ˜แƒ แƒ•แƒ”แƒšแƒ˜ (แƒกแƒแƒฌแƒงแƒ˜แƒกแƒแƒ“)

2

แƒ™แƒ•แƒ˜แƒ แƒ 1 แƒแƒ แƒ˜แƒก แƒžแƒ˜แƒ แƒ•แƒ”แƒšแƒ˜ แƒ™แƒ•แƒ˜แƒ แƒ, แƒ แƒแƒ›แƒ”แƒšแƒ˜แƒช แƒจแƒ”แƒ˜แƒชแƒแƒ•แƒก แƒแƒ› แƒ™แƒ•แƒ˜แƒ แƒ˜แƒก แƒแƒ—แƒฎ แƒแƒœ แƒ›แƒ”แƒข แƒ“แƒฆแƒ”แƒก

3

แƒ™แƒ•แƒ˜แƒ แƒ 1 แƒแƒ แƒ˜แƒก แƒžแƒ˜แƒ แƒ•แƒ”แƒšแƒ˜ แƒ™แƒ•แƒ˜แƒ แƒ, แƒ แƒแƒ›แƒ”แƒšแƒ˜แƒช แƒจแƒ”แƒ˜แƒชแƒแƒ•แƒก แƒ›แƒฎแƒแƒšแƒแƒ“ แƒแƒฎแƒแƒšแƒ˜ แƒฌแƒ˜แƒšแƒ˜แƒก แƒ“แƒฆแƒ”แƒ”แƒ‘แƒก


Example:


Sub example_datediff
    MsgBox DateDiff("d", #1/1/2005#, #2005-12-31#)
End Sub

Please support us!