Date function

xiaoxiao2021-03-06  77

Date function

The date internal function is used to display information about the date and time. They handle the values ​​of DateTime and SmallDateTime and arithmetic operations. The date function can be used in the selection list, where the clause or any place where you can use it.

The value of the DateTime type is stored in the inside into two 4-bytes of integers. The first 4-byte storage base date (January 1, 1900), the number of days before or after. The reference date is the reference date of the system. It is disabled earlier than January 1, 1753. Another 4-byte number stores accurate to 1/300 seconds.

SmallDateTime stores is not as accurate in DateTime. SmallDateTime is stored in two 2-byte integers. The first two bytes store the number of days after the base date, and the other 2 bytes store the number of minutes from the zero point. The date range is from January 1, 1900 to June 6, 2079, and time accurate to minutes.

Function Name Parameters Return Result GetDate () Current System Date and Time Datename (DatePart, Date) gives the date element specified by the DateTime or SmallDateTime as the ASCII string. DATEPART (DATEPART, DATE) gives the date element specified by the DateTime or SmallDateTime in an integer. Datediff (DatePart, Date) The difference between the second and the first date element (for example, month, day, hour) dateadd (DatePart, Number, Date) adds a date value generated after another date.

DateTime, DatePart, Datediff and Dateadd require the year, month, hours, etc. of the date element, the month, month, month. The following table gives each date element, their abbreviations, and the respective range of values. The DateTime function generates the corresponding ASCII value, such as the week of the week.

Date Element Repairment Year YY 1753-9999 Quarter QQ 1-4 Month MM 1-12 Dayofyear DY 1-366 Day DD 1-31 Week WK 0-51 Weekday DW 1-7 (Sunday - Saturday) HOUR HH 0-23 Minute Mi 0-59 Second SS 0-59 Milliseond MS 0-999

Note: The value of Weekday waves is affected by the language of the setting.

example:

Query the monthly points of the given date:

Select Datename (mm, "1997/11/28")

RESULTS: NOVEMBER

The number of months given by the given two dates:

SELECT dateDiff (mm, "1997/09/09", "1997/11/11")

result:

2

Add 5 months for a given date

Select DateAdd (mm, 05, "1997/06/16")

result:

NOV 16 1997 12: 00: 00: 000AM

-

DatePart function accepts the following date element as the number of days:

Calweekofyear Returns New Year

CalyeArofweek returns the number of years

Caldayofyear returns the number of days in the week

Date Elements Abbreviations Calweekofyear CWK 1-52 Calyearofyear CYR 1753-9999 Caldayofweek CDW 1-7 (1 in United States 1)

E.g:

The given date is the first week of the year:

SELECT datePart (CWK, "1997/01/31")

Result: 48

Query the middle part of the given date:

SELECT datePart (CYR, "1997/01/15")

Result: 1997

The date of the query is the day:

Select DatePart (CDW, "1997/11/28")

Result: 5

转载请注明原文地址:https://www.9cbs.com/read-120454.html

New Post(0)