DatePart Function
DatePart āĻĢāĻžāĻāĻļāĻ¨āĻāĻŋ āĻāĻāĻāĻŋ āĻ¤āĻžāĻ°āĻŋāĻā§āĻ° āĻāĻ˛ā§āĻ˛ā§āĻāĻŋāĻ¤ āĻ
āĻāĻļ āĻĒā§āĻ°āĻĻāĻžāĻ¨ āĻāĻ°ā§ āĻĨāĻžāĻā§āĨ¤
DatePart (interval As String, date As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Long
āĻĒā§āĻ°āĻĻāĻžāĻ¨ āĻŽāĻžāĻ¨:
The extracted part for the given date.
interval - A string expression from the following table, specifying the date interval.
interval (string value)
|
āĻŦā§āĻ¯āĻžāĻā§āĻ¯āĻž
|
yyyy
|
āĻŦāĻāĻ°
|
q
|
āĻāĻ¤ā§āĻ°ā§āĻĨāĻžāĻāĻļ
|
m
|
āĻŽāĻžāĻ¸
|
y
|
āĻŦāĻāĻ°ā§āĻ° āĻĻāĻŋāĻ¨
|
w
|
āĻāĻ°ā§āĻŽāĻĻāĻŋāĻŦāĻ¸
|
ww
|
āĻŦāĻāĻ°ā§āĻ° āĻ¸āĻĒā§āĻ¤āĻžāĻš
|
d
|
āĻĻāĻŋāĻ¨
|
h
|
āĻāĻ¨ā§āĻāĻž
|
n
|
āĻŽāĻŋāĻ¨āĻŋāĻ
|
s
|
āĻ¸ā§āĻā§āĻ¨ā§āĻĄ
|
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:
-
#yyyy-mm-dd#
-
#mm/dd/yyyy#
firstdayofweek: An optional parameter that specifies the starting day of a week.
firstdayofweek value
|
āĻŦā§āĻ¯āĻžāĻā§āĻ¯āĻž
|
0
|
āĻ¸āĻŋāĻ¸ā§āĻā§āĻŽā§āĻ° āĻĄāĻŋāĻĢāĻ˛ā§āĻ āĻŽāĻžāĻ¨ āĻŦā§āĻ¯āĻŦāĻšā§āĻ¤ āĻšā§
|
1
|
āĻ°āĻŦāĻŋāĻŦāĻžāĻ° (āĻĄāĻŋāĻĢāĻ˛ā§āĻ)
|
2
|
āĻ¸ā§āĻŽāĻŦāĻžāĻ°
|
3
|
āĻŽāĻā§āĻāĻ˛āĻŦāĻžāĻ°
|
4
|
āĻŦā§āĻ§āĻŦāĻžāĻ°
|
5
|
āĻŦā§āĻšāĻ¸ā§āĻĒāĻ¤āĻŋāĻŦāĻžāĻ°
|
6
|
āĻļā§āĻā§āĻ°āĻŦāĻžāĻ°
|
7
|
āĻļāĻ¨āĻŋāĻŦāĻžāĻ°
|
firstweekofyear: An optional parameter that specifies the starting week of a year.
firstweekofyear value
|
āĻŦā§āĻ¯āĻžāĻā§āĻ¯āĻž
|
0
|
āĻ¸āĻŋāĻ¸ā§āĻā§āĻŽā§āĻ° āĻĄāĻŋāĻĢāĻ˛ā§āĻ āĻŽāĻžāĻ¨ āĻŦā§āĻ¯āĻŦāĻšā§āĻ¤ āĻšā§
|
1
|
āĻŦāĻāĻ°ā§āĻ° ā§§āĻŽ āĻ¸āĻĒā§āĻ¤āĻžāĻšāĻāĻŋ āĻšāĻ˛ā§ ā§§āĻ˛āĻž āĻāĻžāĻ¨ā§ā§āĻžāĻ°āĻŋ āĻ¸āĻŽā§āĻŦāĻ˛āĻŋāĻ¤ āĻ¸āĻĒā§āĻ¤āĻžāĻš (āĻĄāĻŋāĻĢāĻ˛ā§āĻ)
|
2
|
āĻ¸āĻĒā§āĻ¤āĻžāĻš ā§§ āĻšāĻ˛ā§ āĻ¸ā§āĻ āĻŦāĻāĻ°ā§āĻ° āĻāĻžāĻ° āĻ
āĻĨāĻŦāĻž āĻ¤āĻ¤ā§āĻ§āĻŋāĻ āĻĻāĻŋāĻ¨ āĻŦāĻŋāĻļāĻŋāĻˇā§āĻ āĻĒā§āĻ°āĻĨāĻŽ āĻ¸āĻĒā§āĻ¤āĻžāĻš
|
3
|
āĻ¸āĻĒā§āĻ¤āĻžāĻš ā§§ āĻšāĻ˛ā§ āĻ¨āĻ¤ā§āĻ¨ āĻŦāĻāĻ°ā§āĻ° āĻļā§āĻ§ā§āĻŽāĻžāĻ¤ā§āĻ° āĻĻāĻŋāĻ¨ āĻŦāĻŋāĻļāĻŋāĻˇā§āĻ āĻĒā§āĻ°āĻĨāĻŽ āĻ¸āĻĒā§āĻ¤āĻžāĻš
|
Sub example_datepart
MsgBox DatePart("ww", #01/02/2005#) ' displays 2 because weeks start on Sunday
MsgBox DatePart("ww", #12/31/2005#) ' displays 53
MsgBox DatePart(date:=#2005-12-30#, interval:="q") ' displays 4
End Sub