About the date calculation problem of ASP

Source: Internet
Author: User
Tags numeric time interval

Returns the date that the specified time interval has been added.

DATEADD (interval, number, date)
Parameters
Interval
Required option. A string expression that represents the time interval to add. For numeric values, see the "Settings" section.
Number
Required option. Numeric expression that represents the number of time intervals to add. Numeric expressions can be positive (get future dates) or negative numbers (get past dates).
Date
Required option. Variant or text to be added to the interval representation date.
Set up
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
N Minutes
s seconds

Description
You can add or subtract a specified time interval from a date by using the DATEADD function. For example, you can use DATEADD to calculate the date 30 days from today or 45 minutes from now. To add a time interval of "Day" to date, you can use the number of days per year (y), day (d), or number of days of the Week (W).

The DATEADD function does not return an invalid date. The following example adds one months to January 31, 95:

Newdate = DateAdd ("M", 1, "31-jan-95")
In this example, DATEADD returns February 28, 95, not February 31, 95. If date is January 31, 96, it returns February 29, 96, because 1996 is a leap year.

If the calculated date is before 100 A.D., an error is generated.

If number is not a Long value, it is rounded to the nearest integer before being evaluated.


eg

The problem of calculating the date difference in ASP
<%
fzdxsj= #2006 -07-01# ' past time or ' 2006-7-1 ' can also be!
Data=datediff ("D", Fzdxsj,date)
Response. Write ("<br/><br/> from 2006-7-1" &data& "Day <br/>")

' Set description
' YYYY year
' Q Quarter
' M month
' Y number of days in a year
' D Day
' W number of days in a week
' WW Week
' H hour
' N minutes
' s seconds

Response. Write ("Plus month, year, day, time ==<br/>")
Newdate = DateAdd ("M", 1, "31-jan-95")
Response. Write (Newdate)

%>
<script language=vbscript>
document.write DateAdd ("D",-15, "2002-11-08")
</script>
<%
Today=day (date ())
Newd=dateadd ("D", 15,dateserial (Date ()), Month (date ()), today)
Response.Write newd
%>

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.