SQL Server DATEPART()函数的使用
来源:未知 责任编辑:责任编辑 发表时间:2014-01-20 07:54 点击:次
DATEPART() 函数用于返回日期/时间的单独部分,比如年、月、日、小时、分钟等等。
语法格式:
Sql代码
DATEPART(datepart,date)
date 参数是合法的日期表达式:

示例:
分别查询出日期-www.2cto.com-为第几周(week_date),
处于哪一年(year_date),
处于哪一月(month_date),
是当年中第几天( the_year_date)
Sql代码
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;
结果如下:

作者 wangxiao5530
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>