Date and time functions
These scalar functions perform actions on the date and time input value and return a string, numeric value, or date and time value.
The following table lists the date and time functions and their deterministic properties. For more information on function determinism, see the deterministic functions and non-definitective functions.
Function Deterministic DateAdd has deterministic DateDiff having deterministic DateName does not have deterministic DatePart to have certain determinism in addition to DATEPART (DW, date). DW is the date part of the working day, depending on the value set by Set DateFirst set by setting a weekly week. DAY has deterministic getDate does not have deterministic GetCdate without deterministic MONTH has certain deterministic year
Dateadd
On the basis of adding a period of time to the specified date, the new datetime value is returned.
DATEADD (DATEPART, NUMBER, DATE) DATEPART is the parameter that specifies which part of the date you return to the new value. The following table lists the date and abbreviations of Microsoft® SQL ServerTM recognition.
Date Some Abbreviations Yeary, YYYYQUARTERQQ, QMONTHMM, MDAYOFYEARDY, YDAYDD, DWEEKWK, WWHHHHMINUTEMI, NSECONDSS, SMILLISECONDMS - Sample Add 1 Day SELECT DATEADD (Day, 1, '2004-09-18 ') - Return: 2004-09-19 00: 00: 00.000 2.Datediff Returns the number of date and time boundaries across two specified dates. Syntax Datediff (DatePart, StartDate, Enddate) Parameter DatePart is a parameter that specifies which part of the date to calculate the difference. The following table lists the date and abbreviations of Microsoft® SQL ServerTM recognition.
Date Some Abbreviations Yearyy, YYYYQUARTERQQ, QMONTHMM, MDAYOFYEARDY, YDAYDD, DWEEKWK, WWHHHMINUTEMI, NSECONDSS, SMILLISECONDMS - Sample '2004-09-01' Is a difference between the '2004-09-18'? SELECT dateDiff (day, '2004-09-01', '2004-09-18') - Return 17 3.Datename
Returns a string representing the specified date part of the specified date.
grammar
Datename (DatePart, Date)
parameter
DatePart
It is a parameter that specifies the date part of the returned. The following table lists the date and abbreviations of Microsoft® SQL ServerTM recognition.
Date Some Abbreviations Yearyy, YYYYQUARTERQQ, QMONTHMM, MDAYOFYEARDY, YDAYDD, DWEEKWK, WWWEEKDAYDWHHHMINUTEMI, NSECONDSS, SMILLISECONDMS
- Example
Ask '2004-09-19' Is the week?
Select Datename (DW, '2004-09-19') - Return 'Sunday'
If required is English:
Set Language English - Setting language Select Datename (DW, '2004-09-19') - Back: Sundayset Language Simplified Chinese - Set the language Back
4. DatePart
Returns an integer that represents the specified date part of the specified date.
grammar
DatePart (DatePart, Date)
parameter
DatePart
It is a parameter that specifies the date part of the returned. The following table lists the date and abbreviations of Microsoft® SQL ServerTM recognition.
Date Some Abbreviations Yearyy, YYYYQUARTERQQ, QMONTHMM, MDAYOFYEARDY, YDAYDD, DWEEKWK, WWWEEKDAYDWHHMINUTEMI, NSECONDSS, SMILLISECONDMS This example assumes that the date is May 29.
Select DatePart (Month, getdate ())
Go
The following is the result set:
-----------
5
(1 row (s) affected)
5.day
Returns an integer of the date part of the day that represents the specified date.
Syntax DAY (DATE) 6.Getdate Returns the current system date and time by pressing the DateTime value. Grammatical getDate () 7 getcdate Returns the datetime value indicating the current UTC time (world time coordinate or GMT). The current UTC time is available from the current local time and time zone settings in the computer operating system running SQL Server. Grammatical getcdate () 8.month () and Year () Saix the month, the year's integer part Note: Flexible use date time function, take more consideration!