1. Syntax
Datepart (datepart, date) Parameters
Datepart
YesIntegerIs part of the date (date or time value. The following table lists all valid datepart parameters. The user-defined equivalent variable is invalid.
Datepart
T-SQL time operations (dateadd, datediff, datepart, datename), datepartdatename
-- 1. current System Date and Time select getdate () -- 09:27:27. 277--2. the Time Operation dateadd returns the new datetime value dateadd (datepart, number, date) based on a period of time added to the specified date. Note: datepart: year (yy, yyyy) | quarter (qq, q) | month (mm, m)
Tag:sql database --1. Current system date, time select GETDATE ()--2015-01-06 09:27:27.277--2. The time operation DateAdd returns a new datetime value DATEADD (datepart, on the basis of adding a period of time to a specified date) number,date) Note: datepart:year (yy, yyyy) | Quarter (QQ,Q) | Month (mm,m) | Week (WW,WK) | Day (Dd,dy) | Hour (h) | Minute (Mi,n) | Second (ss,s) | The millisecond (MS) Date parameter is a valid date expression. The numb
Tags: englishromcopytimegroup by date settings mon language Tags: datepart function SQL used date month year grouping group by group 2013-12-26 15:31 20764 People read reviews (1) Favorite report Category: SQL Server (21) Copyright notice: This article for Bo Master original article, not allowed to reprint without Bo master. [SQL] View plain copy--take 2013-12-10 12:56:55 for example--convert (nvarchar (ten), createdate,120) = 2013-12-10--
* The datepart () function allows you to conveniently retrieve all parts of the period.* Date: 18:15:36. 513* YY: 2006 of the year* Mm: 7 months* DD: 2 days in the month* DY: 183 days in the year* WK: week 27 in the year* DW: The day in the week.* QQ: Quarter 3 of the year* Hh: 18 hours* Mi: 15 minutes* Ss: 36 seconds* The following simple statements demonstrate the obtained results:*/
Select getdate ()Select date
Label:Definition and usageThe DATEPART () function is used to return a separate part of a date/time, such as year, month, day, hour, minute, and so on.GrammarDATEPART (Datepart,date) The date parameter is a valid day expression. The datepart parameter can be the following value:
DatePart
Abbrevia
DatePart function
Returns the specified portion of a given date.
DatePart(interval, date[, firstdayofweek[, firstweekofyear]])
Arguments
Interval
Required option. A string expression represents the time interval to return. For numeric values, see the "Settings" section.
Date
Required option. The date expression to evaluate.
Firstdayof Week
Options available. Specifies the constant for the first day of the w
DatePart (interval, date[, firstdayofweek[, FirstWeekOfYear])The syntax for the DatePart function has the following parameters:
Parameter descriptionInterval must be selected. A string expression that represents the time interval to return. For numeric values, see the "Settings" section.Date must be selected. The date expression to evaluate.Firstdayof Week optional. Specifies the constant for the first day
Town Field Poem:——— Dream who feel, the water month Build blog. Baiqian tribulation, only know the vicissitudes of the world.——— today holds the Buddhist language, the technology is boundless willing to learn. Willing to do what you learn, cast a conscience blog.——————————————————————————————————————————1 Code1 -- returns how many milliseconds this second has passed 2 Select DatePart (Millisecond,getdate())2 Show———————————————————————————————————————
These functions in fact, many online data, but in order to facilitate their own memory, I still decided to write a bit, all say good memory than bad writing, so or write a bit more.The cast () function essentially converts one type to another, such as converting a string type to a time type: SELECT CAST (' 2011-10-2 ' as datetime), or convert the numeric type to a string type: SELECT CAST (1 as BIGINT) The CONVERT () function is mainly used to display date/time data in different formats: conve
The date and time functions in SQL Server are always problematic in this regard. So, I will summarize what I mainly useDatepart(Month, getdate (). This item can be set to day (now () in access. Unfortunately, the day () in SQL Server does not support parameters.Date and time functions in SQL Server
These scalar functions operate on the input values of date and time, and return a string, numeric value, or Date and Time Value.
The following table lists Date and Time Functions and Their determinist
Take the date 2017-12-11 (Monday) as an example
one or one-like usage
Select DATEPART (Weekday, ' 2017-12-11 ')
Results: 2
Description: Due to MS SQL default Sunday is the 1th day of one weeks, so 2017-12-11 Monday on the 2nd day of one weeks. So analogy: 1. 7 represents the Sunday. Saturday
Ii. setting Monday as the 1th day of one weeks
Set Datefirst 1 -This sentence will be set in Monday for the 1th day of one weeks.
Select
Tags: code pre PNG improved technology sharing database second technology BSPTown Field Poem:——— Dream who feel, the water month Build blog. Baiqian tribulation, only know the vicissitudes of the world.——— today holds the Buddhist language, the technology is boundless willing to learn. Willing to do what you learn, cast a conscience blog.—————————————————————————————————————————— 1 Code 1 -- returns the current number of seconds
2 Select DatePart (Se
Tags: com show base pre error image get http minTown Field Poem:——— Dream who feel, the water month Build blog. Baiqian tribulation, only know the vicissitudes of the world.——— today holds the Buddhist language, the technology is boundless willing to learn. Willing to do what you learn, cast a conscience blog.—————————————————————————————————————————— 1 Code 1 -- back now how many minutes
2 Select DatePart (Minute,getdate()) 2 Show ———————————
Tags: hard to learn log data return technology share date. com Today's contentTown Field Poem:——— Dream who feel, the water month Build blog. Baiqian tribulation, only know the vicissitudes of the world.——— today holds the Buddhist language, the technology is boundless willing to learn. Willing to do what you learn, cast a conscience blog.—————————————————————————————————————————— 1 Code 1 -- return today is the day of the year
2 Select DatePart (Day
Tags: language blog PNG program scientific research color sel. COM blog postTown Field Poem:——— Dream who feel, the water month Build blog. Baiqian tribulation, only know the vicissitudes of the world.——— today holds the Buddhist language, the technology is boundless willing to learn. Willing to do what you learn, cast a conscience blog.—————————————————————————————————————————— 1 Code 1 -- back to what year
it was today 2 Select DatePart (year,getd
Town Field Poem:——— Dream who feel, the water month Build blog. Baiqian tribulation, only know the vicissitudes of the world.——— today holds the Buddhist language, the technology is boundless willing to learn. Willing to do what you learn, cast a conscience blog.——————————————————————————————————————————1 Code1 -- View the current time for easy comparison 2 Select getdate ()3Selectdatepart(month,getdate())2 Show——————————————————————————————————————————The essence of the blog, in the technical p
The similarities and differences between the DATENAME function and the DATEPART function in SQL functions:
Syntax: Datename ( datepart ,date ) and datepart ( datepart , date )
Description: The Datename function obtains the name, according to the different SQL engine version different and obtains the difference result;
Label:DATEPARTReturns an integer representing the specified date portion of the specified date.GrammarDATEPART(datepart,date)ParametersDatePart is a parameter that specifies the date part that should be returned. The following table lists the date parts and abbreviations identified by Microsoft®sql Server™.
Date Part
Abbreviations
Year
YY, yyyy
Quarter
QQ, Q
Month
MM, M
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.