TEST===>Sqlserver中获取年月日时分秒

时间:2022-10-24 12:58:23

可以用两种方法获取

1.

select GETDATE() as '当前日期', DateName(year,GetDate()) as '年', DateName(month,GetDate()) as '月', DateName(day,GetDate()) as '日', DateName(dw,GetDate()) as '星期', DateName(week,GetDate()) as '周数', DateName(hour,GetDate()) as '时', DateName(minute,GetDate()) as '分', DateName(second,GetDate()) as '秒'

2.第二种

年:YEAR(GETDATE())

月:MONTH(GETDATE())

日:DAY(GETDATE())