To get the number of months from the current month to a certain time in the past, asp uses the DateDiff function to implement how asp can realize the number of months from the current month to a certain time in the past.
For example, today is January 2011. I want to know how many months there are between March 2010 and March 2010. The best answer is
<%=datediff(m, 2010-03-01, 2011-01-01)%> 2 other answers in total
datediff(m,2010-03-01,2011-01-01)
DateDiff function
Function: Returns the time interval between two dates.
Syntax: DateDiff(interval, date1, date2 [, firstdayofweek][, firstweekofyear]])
Syntax parameters:
interval is required. A string expression used to calculate the time interval between date1 and date2. See the Settings section for numerical values.
date1, date2 are required. Date expression. Two dates used for calculation.
firstdayofweek Optional. A constant that specifies the first day of the week. If not specified, it defaults to Sunday. See the Settings section for numerical values.
firstweekofyear Optional. Constant that specifies the first week of the year. If not specified, it defaults to the week of January 1st. See settings section for values
Parameter settings:
The interval parameter can have the following values:
Setting description
yyyy year
q quarter
m month
y the number of days in a year
d day
w Day of the week
ww weeks
h hours
m minutes
s seconds
<%
response.write DateAdd(m,1,Date())
%>
If you don’t understand, please refer to the following:
Date()
Function description: Returns the current system date.
Syntax format: Date()
Parameter description: None
Code example: Date()
Return result: 2004-09-14
DateAdd()
Function description: Returns a changed date.
Syntax format: DateAdd(timeinterval,number,date)
Parameter description: timeinterval is the type of time interval to be increased, such as y, m, d, h, etc.; number is the number of time intervals to be increased; date is the base time for time increase.
Code example: DataAdd(m,1,CDate(2004-09-14 17:12:23))
Return result: 2004-10-14 17:12:23
Here's a trick (for beginners), if number is negative, it's equivalent to subtracting Abs(number) intervals.
DateDiff()
Function Description: Returns the difference between two dates.
Syntax format: DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear>>)
Parameter description: timeinterval represents the type of interval, such as M representing months.
Code example: DateDiff(d,2000-1-1,1999-8-4)
Return result: There are 150 days from 1999-8-4 to 2000.