函数-DatePart

SELECT GETDATE() as '当前日期',
DatePart(yy,GetDate()) as '年, yy, yyyy',
DatePart(q,GetDate()) as '季度, q, qq',
DatePart(dy,GetDate()) as '年中的日, dy, y',
DatePart(m,GetDate()) as '月,m,mm',
DatePart(d,GetDate()) as '日,d,dd',
DatePart(dw,GetDate()) as '星期,dw,w',
DatePart(wk,GetDate()) as '周数 wk,ww',
DatePart(hh,GetDate()) as '时,hh',
DatePart(mi,GetDate()) as '分,mi,n',
DatePart(ss,GetDate()) as '秒,ss,s',
DatePart(ms,GetDate()) as '毫秒,ms',
DatePart(mcs,GetDate()) as '微妙,mcs',
DatePart(ns,GetDate()) as '纳秒,ns'

结果

当前日期
yy, yyyy
季度
q, qq
年中的日
dy, y

m,mm

d,dd
星期
dw,w
周数 wk,ww
hh

mi,n

ss,s
毫秒
ms
微妙
mcs
纳秒
ns
2023-06-30 15:41:04.5972023218163062615414597597000597000000