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



objects constants operators statements functions properties methods







FUNCTION:  DateDiff( )

DateDiff(Interval, Date1, Date2, FirstDayofWeek, FirstWeekofYear)

The DateDiff function calculates the amount of time between two different dates.

There are three mandatory arguments.

Interval

The Interval argument defines the the type of time interval you wish to use to calculate the time difference.

Only the following settings can 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
nMinute
sSecond
Date1

The Date1 argument is the first date.


Date2

The Date2 argument is the second date.


Code:
<%=DateDiff("d", Date, "1/1/2000") %>

Output:
291

The order of the two dates determines if the difference is represented as a positive or negative value.

Code:
<% olddate = #6/26/43# %>
<% nowdate = Now %>
<% =DateDiff("s", nowdate, olddate) %>

Output:
-3130748108

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 that has 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. The output is how many weeks, which are now defined to start on Tuesday, are left between the current date and 1/1/2001.

Code:
<% =DateDiff("w", Date, "1/1/2001", 3) %>

Output:
93

Code:
<% =DateDiff("w", Date, "1/1/2001", VBTUESDay) %>

Output:
93

FirstWeekofYear

The FirstWeekofYea argument must only use the constants or values defined in the Date And Time CONSTANTS which are listed above.

Code:
<% =DateDiff("ww", Date, "1/1/2001", 1, VBFIRSTFOURDayS)%>

Output:
94