Common date functions
SQL Server time and date function detailed, SQL Server, time, date,
1. Current system date, time
Select GETDATE ()
2. DateAdd returns a new datetime value on the basis of adding a period of time to the specified date
For example: Add 2 days to date
Select DATEADD (day,2, ' 2004-10-15 ')--back: 2004-10-17 00:00:00.000
3. DateDiff returns the number of date and time boundaries acr
--Get the current date (for example: YYYYMMDD)Select CONVERT (nvarchar), GETDATE (), 112)--Get the current date (for example: YYYYMMDD hh:MM:ss)Select GETDATE ()--Get the current date (for example: YYYY-MM-DD)Select Datename (Year,getdate ()) + '-' +datename (Month,getdate ()) + '-' +datename (Day,getdate ())--Get the current date (for example: YYYY/MM/DD)Select
Reference:http://www.cnblogs.com/coconut_zhang/archive/2009/02/02/1382598.htmlHttp://blog.itpub.net/14766526/viewspace-1156100/Select GETDATE () as ' current date ',Datename (Year,getdate ()) as ' year ',Datename (Month,getdate ()) as ' month ',Datename (Day,getdate ()) as ' Day ',Datename (Dw,getdate ()) as ' Week ',
that it refers to the @ SQL type, and I actually defined varchar. Sorry, it took a lot of time.
5. Write the stored procedure in SQL
Exec iorderaddpricerule_getaddprice 'cgq', 'sfo', 0, 'fm ', '2017-7-15' spname is followed by a parameter directly. The parameter name = parameter value is not required.
6. Declare @ MSG nvarchar (100 );
Set @ MSG = '''gda''' + ',' + ''' AB ''';
Select * From T_A where a. c
To operate SQL server data over the past two days, you need to set the time, minute, and second of a date field, that is, '2017-11-07 16:41:35. the 033 'is changed to '2017-11-07 00:00:00', so I checked the SQL syntax for datetime-type operations on the Internet and found that implementing this function is very simple.
Update yourtable set yourdatecolumn = convert (char (11), yourdatecolumn, 120!
Not
In this lesson, we will learn how to use the built-in SQL System functions to complete the query job. SQL System functions are commonly used, including string functions, date functions, Aggregate functions, and data type conversion, auto-increment functions, and null functions in other function frameworks. The several functions mentioned later have been used in the previous sections. Today we will learn the
4When @ m between 7 and 9 then 7Else 10 endSelect @ time = datename (year, getdate () + '-' + convert (varchar (10), @ M) + '-01'Select datediff (day, @ time, dateadd (mm, 3, @ time ))
SQL time/Date ProcessingSQL time/Date ProcessingIn SQL statements, time (or date) is often processed. Below are some common statements: latency:Sysdate + (5/24/60/60) latency of 5
Label:SQL Server time Date function detailed, SQL Server, time date,1. Current system date, timeSelect GETDATE ()2. DateAdd returns a new datetime value based on adding a period of time to the specified dateExample: Add 2 days to the dateSelect DATEADD (day,2, ' 2004-10-15 ')--return: 2004-10-17 00:00:00.0003. DateDiff returns the number of date and time boundaries across two specified dates.Select DateDiff (Day, ' 2004-09-01 ', ' 2004-09-18 ')--retur
DatePart (date element, date): Returns the integer of the date part specified by the date element
Datename (date element, date): A date name that returns a date element in the form of a string that specifies the time
DateDiff (date element, date 1, date 2): Returns the difference between two days and converts it to the form of the specified date element
DateAdd (date element, value, date): Returns the new date of date plus value by da
'), today is the week of =datename (weekday, ' 2004-10-15 ')function parameters/FunctionsGetDate () returns the current date and time of the systemDateDiff (INTERVAL,DATE1,DATE2) returns the difference between Date2 and date1 two dates in the interval specified date2-date1DATEADD (interval,number,date) with the date specified in interval, plus numberDatePart (interval,date) returns the integer value corresponding to the specified portion of the date,
SQL Statistics this week, this month, next week, the next month SQL statement/*Table structure
Student (s#,sname,sage,ssex)--s# student number, sname student name, Sage birth date, ssex student gender
Save some data
INSERT into Student values (' ', n ' wwww.111cn.net ', ' 1990-01-01 ', n ' Men ')
INSERT into Student values (' ", N ' money electricity ', ' 1990-12-21 ', n ' Men ')
INSERT
1. Date and time functions in SQL Server1. Current system date, timeSelect GETDATE ()2. DateAdd returns a new datetime value based on adding a period of time to the specified dateExample: Add 2 days to the dateSelect DATEADD (day,2, ' 2004-10-15 ')--return: 2004-10-17 00:00:00.0003. DateDiff returns the number of date and time boundaries across two specified dates. Select DateDiff (Day, ' 2004-09-01 ', ' 2004-09-18 ')--return: 174. DatePart returns an
To create a database:1 CREATE DATABASETest--The name of the database to be created2 on PRIMARY3 (4 --specific description of the database file5NAME='Test_data',--logical name of the master data file6FILENAME='E:\project\Test_data.mdf',--physical name of the master data file7SIZE=5MB,--Initial size of master data file8MAXSIZE=100MB,--maximum growth of the master data file9FileGrowth= the% --growth rate of master data filesTen ) One LOG on A ( - --the specific
specifies its default value as the return value of the function getdate (), like this:
CREATE TABLE Site_log (
Username VARCHAR (40),
Useractivity VARCHAR (100),
EntryDate DATETIME DEFAULT GETDATE ())
Convert Date and time
As you may have noticed, in the example in the previous section, the return value of the function getdate () is displayed only to seconds. In fact, the internal time of the SQL sever can be accurate to the millisecond level (
Tags: Mon sql get Day server TE name date () secondGets the year, month, day, time, minute, and second data for the current date in SQL Server:SELECT GETDATE () as ' current date ',Datename (Year,getdate ()) as ' year ',Datename (Month,getdate ()) as ' month ',Datename (Day,
Label:Select GETDATE () as ' current date ',Datename (Year,getdate ()) as ' year ',Datename (Month,getdate ()) as ' month ',Datename (Day,getdate ()) as ' Day ',Datename (Dw,getdate ()) as ' Week ',Datename (Week,getdate ()) as ' Week number ',
CONVERT (varchar), getDate (), 120) Select CONVERT (VARCHAR), GETDATE (), 23) functions nbsp NBSP parameters/Features Getdat E () NBSP ; Return to the current date and time of the system DateDiff (interval,date1,date2) NBS P Returns the difference between Date2 and date1 two dates in interval specified date2-date1 DATEADD (interval,number,date) interval specified, plus the date after number DatePart (interval,date) nbs
converted value to identify the occurrence of this truncation.9) use the style. Option of the convert () function to display the date and time in different formats. Style is the conversion style number provided by the SQL server system when converting datatime and smalldatetime to a string. Different style numbers have different output formats.VII. Date Functions1. Day (date_expression)Returns the date value in date_expression.
2. Month (date_express
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.