ÄúµÄλÖãºÑ°ÃÎÍøÊ×Ò³£¾±à³ÌÀÖÔ°£¾VBScript£¾VBScript


objects constants operators statements functions properties methods






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.

SETTINGDESCRIPTION
YYYYYear
QQuarter
MMonth
YDay Of Year
DDay
WWeekDay
WWWeek Of Year
HHour
MMinute
SSecond


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.

CONSTANTVALUEDESCRIPTION
VBSUNDay1Sunday
VBMONDay2Monday
VBTUESDay3Tuesday
VBWEDNESDay4Wednesday
VBTHURSDay5Thursday
VBFRIDay6Friday
VBSATURDay7Saturday
VBFIRSTJAN11Week of January 1
VBFIRSTFOURDayS2First week of the year thathas at least four days
VBFIRSTFULLWeek3First full week of the year
VBUSESYSTEM0Use the date format of the computer's regionsl settings
VBUSESYSTEMDayOfWeek0Use 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