1. Cast
Cast (columnname as nvarchar (30) columnname is converted to bytes
2. Round
Round (columnname, 2) takes two decimal places
3. Convert
Select convert (varchar (12), getdate (), 102) -- 2012.12.26
Select convert (varchar (12), getdate (), 111) -- 2012/12/26
Select convert (varchar (12), getdate (), 112) -- 20121226
Select convert (varchar (23), getdate (), 121) -- 23:21:56. 910
Select convert (varchar (19), getdate (), 120) -- 23:21:56
Select convert (varchar (10), getdate (), 120) --
Select convert (varchar (8), getdate (), 114) -- 23:21:56
4. getdate ()
Select getdate () -- 2012-12-26 23:21:56. 910
5. datepart
Select datepart (year, getdate () --- 2012
Select datepart (quarter, getdate () -- 4
Select datepart (month, getdate () -- 12
Select datepart (day, getdate () -- 26
Select Day (getdate () -- 26
Select datepart (dy, getdate () -- 361 [add dy to day of year, the day of the year]
Select datepart (weekday, getdate () -- 4 [minus 1, because foreign countries are different from China, indicating Today's Wednesday]
Select datepart (Week, getdate () -- 52 [week 52nd]
Select datepart (hour, getdate () -- 23
Select datepart (minute, getdate () -- 21
Select datepart (second, getdate () -- 56
Select datepart (millisecond, getdate () -- 910
6. datename
Select datename (day, getdate () -- 26
Select datename (dy, getdate () -- 361
Select datename (weekday, getdate () -- Wednesday [note the difference with datepart]
Select datename (Week, getdate () -- 52
7. dateadd, time Addition
Select dateadd (day, 3, getdate () -- 23:21:56. 910
Select dateadd (month, 3, getdate () -- 23:21:56. 910
8. datediff, time subtraction, followed by time minus the previous time difference
Select datediff (day, '2017-12-20 ', getdate () -- 6
Select datediff (month, '2014-12-20 ', getdate () -- 0
9. Rand
Select cast (floor (RAND (checksum (newid () * 100) as INT)