Date plus days

Source: Internet
Author: User

How to Use the dateadd function in ASP

String expression, indicating the time interval to be added. For values, see "Settings.
Returns the date of the specified interval.

Dateadd (interval, number, date)

Parameters
Interval

Required.

Number

Required. Numeric expression, indicating the number of time intervals to be added. A numeric expression can be a positive number (to get the future date) or a negative number (to get the past date ).

Date

Required. Variant or the text that represents the date to add interval.

Set
The interval parameter can have the following values:

Yyyy
Q quarter
M month
Y number of days in a year
D
Number of days per week
WW week
H hour
N minutes
S seconds

Description
The dateadd function can be used to add or subtract a specified time interval from a date. For example, you can use dateadd to start from the day 30 days later or 45 minutes later than the current day. To add a time interval in the unit of "day" To date, you can use "day of the year" ("Y"), "day" ("D ") or "the number of days in a week" ("W ").

The dateadd function does not return an invalid date. In the following example, we will add a month to April January 31:

Newdate = dateadd ("M", 1, "31-Jan-95 ")
In this example, dateadd returns February 28, instead of February 31. If date is January 31, the return value is February 29, because 1996 is a leap year.

If the calculation date is before January 1, 100 AD, an error occurs.

If the number is not a long value, the first rounding is the nearest integer.

SQL Server

Dateadd

Returns a new datetime value based on a specified date.

Syntax

DATEADD ( datepart , number, date )

Parameters

Datepart

Is a parameter that specifies which part of the date should be returned to the new value. The following table lists Microsoft SQL server? Recognize the date and abbreviation.

Date abbreviations: yearyy, yyyyquarterqq, qmonthmm, mdayofyeardy, ydaydd, dweekwk, wwhourhhminutemi, nsecondss, smillisecondms

Number

Is used to addDatepart. If you specify a value that is not an integer, the fractional part of the value is discarded. For exampleDatepartSpecify dayNumberSpecify 1.75DateIt will increase by 1.

Date

Is an expression that returns the datetime, smalldatetime, or date format string. For more information about the specified date, see.

If you only specify the last two digits of the year, the number of the last two digits smaller than or equal to the value of the "two-digit year deadline" configuration option is in the same century as the end year. The last two-digit number greater than the value of this option is in the century before the end of the century. For example, if two digit year cutoff is 2049 (default), 49 is interpreted as 2049,2050 as 1950. To avoid blurring, use a four-digit year.

Return type

Returns datetime, but ifDateThe parameter is smalldatetime, And the return value is smalldatetime.

Example

This example prints a list of the title time structures in the pubs database. This time structure indicates the current release date plus 21 days.

USE pubsGOSELECT DATEADD(day, 21, pubdate) AS timeframeFROM titlesGO

The following is the result set:

timeframe                    --------------------------- Jul 3 1991 12:00AM           Jun 30 1991 12:00AM          Jul 21 1991 12:00AM          Jul 13 1991 12:00AM          Jun 30 1991 12:00AM          Jul 9 1991 12:00AM           Mar 14 1997   5:09PM          Jul 21 1991 12:00AM          Jul 3 1994 12:00AM           Mar 14 1997   5:09PM          Nov 11 1991 12:00AM          Jul 6 1991 12:00AM           Oct 26 1991 12:00AM          Jul 3 1991 12:00AM           Jul 3 1991 12:00AM           Nov 11 1991 12:00AM          Jul 3 1991 12:00AM           Jul 3 1991 12:00AM           (18 row(s) affected)# ASP Column

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.