1. Common date methods (the following getdate () = '2017-11-08 13:37:56. 123 ')
(1) datename (datepart, date)
Returns the string that represents the specified date part of the specified date. For details about datepart, see the following list.
Select datename (day, getdate ()-returns 8
(2) datepart (datepart, date)
Returns an integer that represents the specified date of a specified date.
Select datepart (y
Sqlserver:selectgetdate () 2.datediff (' s ', ' 2005-07-20 ', ' 2005-7-25 22:56:32 ') The return value is 514592 s DateDiff (' d ', ' 2005-07-20 ', ' 2005-7-2522:56:32 ') return value 5 days The return value of 3.DatePart (' W ', ' 2005-7-2522:56:32 ') is 2 Monday (Sunday is 1, Saturday is 7) DatePart (' d ', ' 2005-7-2522:56:32 ') The return value is 25 25th # datepart (' y ', ' 2005-7-2522:56:32 ') The return value is 206 that is the No. 206 day of the Year datepart (' yyyy ', ' 2005-7-25 22
6. Basic SQL sorting (date and time data types, conversion functions) and SQL data typesDate and Time Data Type
* System constant:
@ DATEFIRST (returns the current time)DATEADD
Increase time
Syntax: DATEADD (datepart, number, date)
Select DATEADD (YEAR, 2, '1970-11-2 ')
DATEDIFF
Distance between two dates
Select DATEDIFF (YEAR, '2017-7-18 ', '2017-11-2 ')
DATENAME
SQL statement gets a specific date
1. The first day of one months
Select DATEADD (mm, DATEDIFF (Mm,0,getdate ()), 0)
2. Monday of this week
Select DATEADD (wk, DATEDIFF (Wk,0,getdate ()), 0)
3. The first day of the year
Select DATEADD (yy, DATEDIFF (Yy,0,getdate ()), 0)
4. First day of the quarter
Select DATEADD (QQ, DATEDIFF (Qq,0,getdate ()), 0)
5. The middle of the day
Select DATEADD (DD, DATEDIFF (Dd,0,getdate ()), 0)
6. Last day of l
The current date and time DateDiff (INTERVAL,DATE1,DATE2) returns the difference between Date2 and date1 two dates date2-date1 DateAdd (interval,number, in the interval specified manner) Date) The integer value Datename (interval,date) that is specified in interval, plus number after number DatePart (interval,date) returns the date, interval the specified part. Returns the string name corresponding to the specified part of the date, interval The sett
datename (interval,date) that corresponds to the specified part of the date, interval returns the string name for the specified portion of the date, intervalThe setting values for the parameter interval are as follows:Value abbreviations (SQL Server) Access and ASP descriptions YearYy yyyy Year1753 ~ 9999Quarter Qq Q season1 ~ 4MonthMm m Month 1~ A Day of YearDy y number of days of the year, the Day of
Label:One, SQL Server date-time functionsDate 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.Selec
Tags: compare IDT table Structure decimal des strings index COM default1. Remote Login mode 2. Query the first 100 data Select top * FROM [dbo]. [Flow_share_day_tax] 3. Get the system time SELECT GETDATE () as ' current time ' Get other Time: DATEPART () returns an integer representing the specified date part of the specified date SELECT DATEPART (year, GETDATE ()) as ' years 'SELECT DATEPART (month, GETDATE ()) as ' month 'SELECT DATEPART (Day, GETDATE ()) as ' days 'SELECT DATEPART (DW, GETDA
()
> return line The current date and time of the EC
datediff (interval,date1,date2)
Returns the difference between date2 and date1 two dates, as specified by interval date2-date1
dateadd (interval,number,date)
datepart (interval,date)
Return date, interval the integer value of the specified section
datename (interval,date)
returns date, interval the string na
, dateadd (day, 1-datepart (weekday, @ date), @ date )) as 'first day of next week, Sunday' -Simplified select dateadd (day, 8-datepart (weekday, @ date), @ date) as' first day of next week, sunday' -next Sunday, independent of the SQL Server language version or @ datefirst select dateadd (week, 1 + datediff (week,-1, @ date),-1) as 'Next Sunday' -or select dateadd (Week, datediff (week,-1, @ date), 6) as 'Next Sunday' go
-determine the day of th
Tags: des style blog Class tar extUse SQL statements to query data for a date in a week
SELECT * from Shoporder where DateDiff (Week,ordtime,getdate ()-1) =0//query date of the day on the first anniversary of the data SELECT * from Shoporder where DateDiff (Day,ordtime,getdate ()-1) =0//query all data for the current day SELECT * from A where DateDiff (D,datetime,getdate ()) SELECT * from A WHERE DATEDIFF (M, Shijian, GETDATE ())
Tags: date format nio Data code technology error closed Err CharIf you want to manipulate a table to have a certain understanding of the table, then you can use two sentences SQL to intuitively understand the table structure sp_help table name; And sp_columns table name; There are also some very basic operations, such as: 1, query the current system date: SELECT GETDATE (); 2. Execute function SELECT dbo. F_func_log_batch_no (); 3. Stitching data: UNI
CONVERT (varchar), GETDATE (), 126): 2006-05-16t10:57: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: Add 2 days to the dateSelect DATEADD (day,2, ' 2004-10-15 ')--return
(Dd,6-datepart (day,getdate)), getdate)), 0) 13. Last day of the yearSELECT DateAdd (Ms,-3,dateadd (yy, DATEDIFF (Yy,0,getdate ()) +1, 0)). 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.000 3. DateDiff returns the number of
() month () --No seconds Day () Select year (' 1999-1-1 ') Select Month (GetDate ()) Determine if the date is correct isdate () Select IsDate (' 2000-2-31 ') ----return bit type , False is 0,true is 1 Add Time DateAdd (A, B, D)----a add what type (year,month,day) B plus how many C to who add Select DATEADD (year,5, ' 2000-1-1 ') Returns the day of the Week Datename (weekday, time)-The returned value is the same as the string datepart can return a
To get the day of the week, you need to use the DATE function in SQL Server: Datename ().Today is the day of the week, Example 1: Set Language N ' 中文版 ' select Datename (Weekday, GETDATE ()) WednesdayToday is the day of the week, Example 2: Set Language N ' Simplified Chinese ' select Datename (Weekday, GETDATE (
I. SQL Server Date and Time FunctionsDate and time functions in SQL Server1. Current System Date and TimeSelect getdate ()2. dateadd returns a new datetime value based on a period of time added to the specified date.For example, add 2 days to the dateSelect dateadd (day, 2, '2017-10-15 ') -- Return: 2004 00:00:00. 0003. datediff returns the number of date and time boundaries across two specified dates.Selec
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.