Datediff,dateadd in ASP to get the number of months in the current month from a previous time

Source: Internet
Author: User
Tags constant date1 numeric time interval

If today is January 2011, I would like to know from March 2010, calculate this is a few months the best answer
<%=datediff ("M", "2010-03-01", "2011-01-01")%> other answers total 2

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 must be selected. A string expression that is used to calculate the time interval between Date1 and Date2. For numeric values, see the "Settings" section.
Date1, Date2 must choose. An expression of a date. Two dates used for the calculation.
FirstDayOfWeek Optional. Specifies the constant for the first day of the week. If not specified, the default is Sunday. For numeric values, see the "Settings" section.
FirstWeekOfYear Optional. Specifies a constant for the first week of the year. If not specified, the default is the week of January 1. For numeric values, see the "Settings" section

Parameter settings:

The interval parameter can have the following values:
Set description
YYYY years
Q Quarter
M month
Y number of days in a year
D-Day
W Number of days in a week
WW Week
H hours
M minutes
s seconds

<%
Response.Write DateAdd ("M", 1,date ())
%>
Do not understand the words 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 date that has been changed.
Syntax format: DATEADD (timeinterval,number,date)
Parameter description: TimeInterval is to increase the type of time interval, such as "Y", "M", "D", "H" and so on; Number is the amount of time interval to increase; Date is the base time for the increase in time.
code example: Dataadd ("M", 1,cdate ("2004-09-14 17:12:23")
Returned results: 2004-10-14 17:12:23
Here's a tip (for starters), if number is negative, it is 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 time between intervals, such as "M" for "month".
code example: DateDiff ("D", "2000-1-1", "1999-8-4")
Return result: From 1999-8-4 to 2000 there are 150 days.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.