DateDiff funktsioon

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

Süntaks:


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

Tagastusväärtus:

Arv.

Parameetrid:

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

interval (string value)

Selgitus

yyyy

Aasta

q

Kvartal

m

Kuu

y

Päev aastas

w

Nädalapäev

ww

Nädal aastas

d

Päev

h

Tund

n

Minut

s

Sekund


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

Selgitus

0

Kasutatakse süsteemi vaikeväärtust

1

Pühapäev (vaikimisi)

2

Esmaspäev

3

Teisipäev

4

Kolmapäev

5

Neljapäev

6

Reede

7

Laupäev


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

firstweekofyear value

Selgitus

0

Kasutatakse süsteemi vaikeväärtust

1

Nädal 1 on nädal, mis sisaldab kuupäeva 1. jaanuar (vaikimisi)

2

Nädal 1 on nädal, mis sisaldab aasta nelja või enamat päeva.

3

Nädal 1 on nädal, mis sisaldab ainult alanud aasta päevi.


Näide:


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