When doing a project, you often need to process the stored time in the database before performing the operation. So I have summarized some.
-- 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 ())