This article describes some common time and date processing functions in SQL, including the-DATEPARTDATEDIFFCONVERTgetdate () DATEADD functions.
This article describes some commonly used time and date processing functions in SQL, including the-DATEPART DATEDIFF CONVERT getdate () DATEADD functions.
-- Get the curren
SQL DateWhen we work on dates, the hardest task is to ensure that the date you insert is formatted to match the format of the date column in the database.As long as the data contains only the date parts, running the query will not be a problem. However, if time is involved, the situation is a little more complicated.Be
SQL Server Chinese version of the default Date field datetime format is YYYY-MM-DD Thh:mm:ss.mmm
For example:
Select GETDATE ()
Sorted out the date format conversion methods that you might often use in SQL Server:
examples are as follows:
Select CONVERT (varchar, GETDATE (), 120)
2004-09-12 11:06:08
Select replace (
Http://www.w3school.com.cn/sql/sql_dates.aspSQL DateWhen we work on dates, the hardest task is to ensure that the date you insert is formatted to match the format of the date column in the database.As long as the data contains only the date parts, running the query will not be a problem. However, if time is involved, t
Label:Date-time functions 1. Get the current date getdate The GETDATE () function returns the date and time of the computer on which the current SQL Server servers are located, in the format of the datetime data type. Its syntax format is GETDATE (). The return value is rounded to the nearest fractional fraction of the second, with a precision of. 333 seconds th
Inter-function 1. Get the current date getdateThe GETDATE () function returns the date and time of the computer on which the current SQL Server servers are located, in the format of the datetime data type. Its syntax format is GETDATE (). The return value is rounded to the nearest fractional fraction of the second, with a precision of. 333 seconds the database 1
// Synchronize the time and date of the SQL _server Server
Procedure TDM. synchronizationsqlserverdatetime ();
VaR
Theserverdatetime: tdatetime; // defines the server time
Thelocaldatetime: _ systemtime; // defines the local system time reference windows
Year, month, day: word; // defines the year, month, and day.
Hour, Min, SEC, msec: word; // defines the time, minute, and second.
Begin
With commonquery do
Query out data, and add data that is not present in the list, and the values of this column are equalSelect App_id,app_secret from Wx_ticket Group by app_id;The data that is queried isapp_id | Expires_in--------------------+------------WXEEC89CDF2D435D10 | 7200WXEEC89CDF2D435D10 | 7200wx9b7bfb5f59df5009 | 7200wx9b7bfb5f59df5009 | 7200wx649ae9eecb72227d | 7200wx649ae9eecb72227d | 7200When using select ' 20150429 '
CONVERT (varchar), GETDATE (), 121): 2006-05-16 10:57:49.700
Select CONVERT (varchar), GETDATE (), 126): 2006-05-16t10:57:49.827
Select CONVERT (varchar), GETDATE (), ():?????????? 1427 10:57:49:907am
In SQL database, there is a class of functions that have to be mentioned, that is, SQL Server datetime function, which is the most common SQL Server process
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 ',Datename (Hour,getdate ()) as ' when ',Datename (Minute,getdate ()) as ' min ',Datename (Second,getdate ()) as ' s 'Results:2009-08-13 23:07:15.403 2009 08 13 Week 433 23 7 15
:49.827Select CONVERT (varchar), GETDATE (), ():???? ?????? 1427 10:57:49:907amSelect CONVERT (varchar), GETDATE (), 131): 18/04/1427 10:57:49:920am2. SQL Server date and time functions1. Current system date, timeSelect GETDATE ()2. DateAdd returns a new datetime value based on adding a period of time to the specified dateExample:
, ", GETDATE ()), ' 1900-02-01 ')14. Get the current day of the weekSelect Datename (Weekday, GETDATE ())15. Current system date, timeSelect GETDATE ()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.000DateDiff returns the number of
corresponding to the specified portion of the date, intervalDatename (interval,date) returns the name of the string that corresponds to the specified part of the date, intervalThe setting values for the parameter interval are as follows:value abbreviation (SQL Server) descriptionYear Yy 1753 ~ 9999Quarter Qq Season 1
.
Example:
Select Datename (Year,getdate ()) as ' year '
Executing the SQL statement above will see the return value of ' 2006 '
The table below lists the most important built-in date functions in SQL Server: function descriptionGETDATE () returns the current date and timeDATEPART () returns a separate part of a
expression: Data_type The data types provided by the target system, including bigint and sql_variant. You cannot use a user-defined data type. Length Optional parameters for nchar, nvarchar, char, varchar, binary, or varbinary data types. Style A date format style whereby DateTime or smalldatetime data is converted to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data type) or a string format style that will float, Real, money,
Label: Automatically add serial numbers via SQL The project often have some document serial number or process serial number is to create a new record after the automatic generation of a number, such as a new process automatically based on the current date automatically add the process flow number, the following descr
time to the specified dateExample: Add 2 days to the dateSelect DATEADD (day,2, ' 2014-10-15 ')--return: 2014-10-17 00:00:00.000--16. DateDiff returns the number of date and time boundaries across two specified dates.Select DateDiff (Day, ' 2004-09-01 ', ' 2004-09-18 ')--return: 17--17. DatePart returns an integer representing the specified date portion of the s
Use convert in SQL server2000 to get the datetime data type style (full)Processing of date data formats, two examples:CONVERT (varchar (16), time one, 20) results: 2007-02-01 08:02/* time is generally a field in the GETDATE () function or data table */CONVERT (varchar (10), time one, 23) Result: 2007-02-01/*varchar (10) represents the format of the date output, w
№ 1: The current date is the week ordinal of this month
Sql> Select To_char (sysdate, ' YYYYMMDD W HH24:MI:SS ') from dual;
To_char (sysdate, ' YY-------------------20030327 4 18:16:09
Sql> Select To_char (sysdate, ' W ') from dual;
T-4
№ 2: The current date is the day of the one week, note that Sunday is the firs
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.