Fonction DatePart

La fonction DatePart renvoie la partie spécifiée de la date.

Syntaxe :


DatePart (interval As String, date As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Long

Valeur de retour :

The extracted part for the given date.

Paramètres :

interval - A string expression from the following table, specifying the date 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


date - The date from which the result is calculated.

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_datepart
    MsgBox DatePart("ww", #12/31/2005#)
    MsgBox DatePart(date:=#1999-12-30#, interval:="q")
End Sub