DATEPART() 函数用于返回日期/时间的单独部分,比如年、月、日、小时、分钟等等。
语法格式:
DATEPART(datepart,date)
date 参数是合法的日期表达式:
示例:
分别查询出日期为第几周(week_date),
处于哪一年(year_date),
扫描二维码关注公众号,回复:
1401705 查看本文章
处于哪一月(month_date),
是当年中第几天( the_year_date)
select InspectionDate, DATEPART(ww,InspectionDate) as week_date, DATEPART(yy,InspectionDate) as year_date, DATEPART(mm,InspectionDate) as month_date, DATEPART(y,InspectionDate) as the_year_date from Inspection.Inspection;
结果如下: