VBScript » Functions » DatePart

Version: 2.0

Syntax:
DatePart(Interval, Date, FirstDayofWeek, FirstWeekofYear)
Interval
The Interval argument designates the the type of time interval.

Only the settings from the Interval Settings table may be used, and you must place the setting inside a pair of double quotes.
Date
The Date argument is the date and time you designate.
FirstDayofWeek
The FirstDayofWeek argument must only use the constants or values defined below in the Date And Time CONSTANTS.
FirstWeekofYear
The FirstWeekofYear argument must only use the constants or values defined in the Date And Time CONSTANTS which are listed above.

The DatePart function returns the designated part of the date.

Interval Settings

SETTING DESCRIPTION
YYYY Year
Q Quarter
M Month
Y Day Of Year
D Day
W WeekDay
WW Week Of Year
H Hour
N Minute
S Second


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

Examples

Code:
<% =Date %>
<% =DatePart("D", Date) %>
Output:
3/16/99 16
Language(s): VBScript
Code:
<% =DatePart("W", 1/1/2000) %>
Output:
7
Explanation:

The weekday is given as a number from the Date And Time CONSTANTS which are listed below. In the example, 7 equals Saturday.

Language(s): VBScript
Code:
<% =DatePart("W", "1/1/2000", 3) %>
Output:
5
Language(s): VBScript
Code:
<% =DatePart("W", "1/1/2000", VBTUESDAY)
%>
Output:
5
Explanation:

In this example, Tuesday is defined to be the first day of the week. Therefore, Saturday becomes the 5th day of the week.

Language(s): VBScript
Code:
<% =DatePart("WW", "12/31/1999", 1, VBFIRSTFULLWeek) %>
Output:
52
Explanation:

This example returns how many full 7 day weeks there were in 1999.

Language(s): VBScript

See Also: