Fonction DateDiff

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

Syntaxe :


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

Valeur de retour :

un nombre.

Paramètres :

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

interval (string value)

Explication

yyyy

Année

q

Trimestre

m

Mois

y

Jour de l'année

w

Jour de la semaine

ww

Semaine de l'année

d

Jour

h

Heure

n

Minute

s

Seconde


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

Explication

0

Utiliser la valeur système par défaut

1

Dimanche (par défaut)

2

Lundi

3

Mardi

4

Mercredi

5

Jeudi

6

Vendredi

7

Samedi


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

firstweekofyear value

Explication

0

Utiliser la valeur système par défaut

1

La semaine 1 est la semaine du 1er janvier (par défaut)

2

La semaine 1 est la première semaine contenant quatre jours ou plus de cette même année

3

La semaine 1 est la première semaine contenant uniquement des jours de la nouvelle année


Exemple :


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