Copy codeThe Code is as follows:
-- Get the current time
Select getdate ()
-- Obtain the current year, month, and day. YY indicates the year, MM indicates the month, DD indicates the day, hh indicates the day, and ss indicates the second.
/*
Year yy 1753--9999 quarter qq 1--4 month mm 1--12 day of year dy 1--366
Day dd 1--31 week wk 1--53 weekday dw 1--7 (Sunday -- Saturday)
Hour hh 0--23 minute mi 0--59 second ss 0--59 milisecond MS 0--999 */
-- DATEPART achieves the same effect as DATENAME. DATEPART returns an integer and DATENAME returns a character.
Select DATEPART (qq, getdate ())
-- Get-d from the previous day; + d from the next day
Select getdate ()-1
-- Obtain the yy, mm, dd, and dd of the two time ranges.
Select DATEDIFF (dd, '2017-7-7 ', getdate ())
-- Convert a date of string type to a date type
Select CONVERT (DATETIME, '2017-8-6 '))
-- Add or subtract year, month, and day on the current time
Select DATEADD (mm,-2, getdate ())