FUNCTION: DatePart( )
DatePart(Interval, Date, FirstDayofWeek, FirstWeekofYear)
The DatePart function returns the designated part of the date.
There are two mandatory arguments.
Interval
The Interval argument designates the the type of time interval.
Only the following settings may be used. You must place the setting inside a pair of double quotes.
SETTING | DESCRIPTION |
YYYY | Year |
Q | Quarter |
M | Month |
Y | Day Of Year |
D | Day |
W | WeekDay |
WW | Week Of Year |
H | Hour |
M | Minute |
S | Second |
Date
The Date argument is the date and time you designate.
Code:
<% =Date %>
<%
=DatePart("D", Date) %>
Output:
3/16/99
16
The weekday is given as a number from the Date And Time CONSTANTS which are listed below. In the example, 7 equals Saturday.
Code:
<% =DatePart("W", 1/1/2000) %>
Output:
7
There are two optional arguments.
FirstDayofWeek
The FirstDayofWeek argument must only use the constants or values defined below in the Date And Time CONSTANTS.
CONSTANT | VALUE | DESCRIPTION |
VBSUNDay | 1 | Sunday |
VBMONDay | 2 | Monday |
VBTUESDay | 3 | Tuesday |
VBWEDNESDay | 4 | Wednesday |
VBTHURSDay | 5 | Thursday |
VBFRIDay | 6 | Friday |
VBSATURDay | 7 | Saturday |
VBFIRSTJAN1 | 1 | Week of January 1 |
VBFIRSTFOURDayS | 2 | First week of the year thathas at least
four days |
VBFIRSTFULLWeek | 3 | First full week of the year |
VBUSESYSTEM | 0 | Use the date format of the computer's regionsl settings |
VBUSESYSTEMDayOfWeek | 0 | Use the first full day of the week as defined by the system settings |
In this example, Tuesday is defined to be the first day of the week.
Therefore, Saturday becomes the 5th day of
the week.
Code:
<% =DatePart("W", "1/1/2000", 3) %>
Output:
5
Code:
<% =DatePart("W", "1/1/2000", VBTUESDay) %>
Output:
5
FirstWeekofYear
The FirstWeekofYear argument must only use the constants or values defined in the Date And Time CONSTANTS which are listed above.
This example returns how many full 7 day weeks there were in 1999.
Code:
<% =DatePart("WW", "12/31/1999", 1,
VBFIRSTFULLWeek) %>
Output:
52