The specific website is not saved, but I am used to saving the code remembered method. Now I am posting it. I hope the original author will be considerate.
Copy codeThe Code is as follows:
--- First day of last month
Select CONVERT (varchar (12), DATEADD (mm, DATEDIFF (mm, 0, dateadd (mm,-1, getdate (), 0), 112)
--- Last day of last month
Select CONVERT (varchar (12), dateadd (MS,-3, DATEADD (mm, DATEDIFF (m, 0, getdate (), 0), 112)
-- 1. display the first day of the month
Select dateadd (mm, DATEDIFF (mm, 0, getdate (), 0)
Select convert (datetime, convert (varchar (8), getdate (), 120) + '01', 120)
-- 2. display the last day of the month
Select dateadd (day,-1, convert (datetime, convert (varchar (8), dateadd (month, 1, getdate (), 120) + '01', 120 ))
SELECT dateadd (MS,-3, DATEADD (mm, DATEDIFF (m, 0, getdate () + ))
-- 3. Last day of last month
SELECT dateadd (MS,-3, DATEADD (mm, DATEDIFF (mm, 0, getdate (), 0 ))
-- 4. the first Monday of the month
Select DATEADD (wk, DATEDIFF (wk, 0, dateadd (dd, 6-datepart (day, getdate (), getdate (), 0)
-- 5. The first day of the year
Select dateadd (yy, DATEDIFF (yy, 0, getdate (), 0)
-- 6. The last day of the year
SELECT dateadd (MS,-3, DATEADD (yy, DATEDIFF (yy, 0, getdate () + ))
-- 7. Last day of last year
SELECT dateadd (MS,-3, DATEADD (yy, DATEDIFF (yy, 0, getdate (), 0 ))
-- 8. The first day of this quarter
Select dateadd (qq, DATEDIFF (qq, 0, getdate (), 0)
-- 9. Monday of the week
Select dateadd (wk, DATEDIFF (wk, 0, getdate (), 0)
-- 10. query records of this month
Select * from tableName where DATEPART (mm, theDate) = DATEPART (mm, GETDATE () and DATEPART (yy, theDate) = DATEPART (yy, GETDATE ())
-- 11. query the records of this week
Select * from tableName where DATEPART (wk, theDate) = DATEPART (wk, GETDATE () and DATEPART (yy, theDate) = DATEPART (yy, GETDATE ())
-- 12 query records of this season. Note: GETDATE () is a function used to obtain the system time.
Select * from tableName where DATEPART (qq, theDate) = DATEPART (qq, GETDATE () and DATEPART (yy, theDate) = DATEPART (yy, GETDATE ())
-- 13. Get the total number of days of the month:
Select DATEDIFF (dd, getdate (), DATEADD (mm, 1, getdate ()))
Select datediff (day, dateadd (mm, datediff (mm, '', getdate (),''), dateadd (mm, datediff (mm ,'', getdate (), '2017-02-01 '))
-- 14. Obtain the current day of the week
Select datename (weekday, getdate ())
Select CONVERT (varchar (12), getdate (), 101) -- 12/28/2007
Select CONVERT (varchar (12), getdate (), 102) -- 2007.12.28
Select CONVERT (varchar (12), getdate (), 103) -- 28/12/2007
Select CONVERT (varchar (12), getdate (), 104) -- 28.12.2007
Select CONVERT (varchar (12), getdate (), 105) -- 28-12-2007
Select CONVERT (varchar (12), getdate (), 106) -- 28 12 2007
Select CONVERT (varchar (12), getdate (), 107) -- 12 28,200 7
Select CONVERT (varchar (12), getdate (), 108) -- 10:06:33
Select CONVERT (varchar (12), getdate (), 109) -- 12 28 2007 1
Select CONVERT (varchar (12), getdate (), 110) -- 12-28-2007
Select CONVERT (varchar (12), getdate (), 111) -- 2007/12/28
Select CONVERT (varchar (12), getdate (), 112) -- 20071228
Select CONVERT (varchar (12), getdate (), 113) -- 28 12 2007 1
Select CONVERT (varchar (12), getdate (), 114) -- 10: 07: 36: 623
Select CONVERT (varchar, getdate (), 120) -- 2007-12-28 10:08:56
Select CONVERT (varchar (10), getdate (), 120) --
Select replace (CONVERT (varchar, getdate (), 120 ),'-',''),'',''),':','') -- 20071228101012