Funzione DateDiff

Restituisce il numero di intervalli di data od ora che trascorrono tra i due valori di data indicati.

Sintassi:


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

Valore restituito:

Un numero.

Parametri:

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

interval (string value)

Spiegazione

yyyy

Anno

q

Trimestre

m

Mese

y

Giorno dell'anno

w

Giorno della settimana

ww

Settimana dell'anno

d

Giorno

h

Ora

n

Minuto

s

Secondo


data1, data2 - Le due date da confrontare.

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

Spiegazione

0

Usa il valore predefinito di sistema

1

Domenica (predefinito)

2

Lunedì

3

Martedì

4

Mercoledì

5

Giovedì

6

Venerdì

7

Sabato


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

firstweekofyear value

Spiegazione

0

Usa il valore predefinito di sistema

1

La settimana 1 è quella che comprende il 1° gennaio (predefinito)

2

La settimana 1 è la prima settimana che comprende quattro o più giorni di quell'anno

3

La settimana 1 è la prima settimana che comprende solo giorni del nuovo anno


Esempio:


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