软件下载吧文章资讯

分类分类

SQL开发知识:sqlserver之datepart和datediff应用查找当天上午和下午的数据

2024-02-07 12:09作者:下载吧

DATEPART() 函数用于返回日期/时间的单独部分,比如年、月、日、小时、分钟等等。

DATEDIFF() 函数返回两个日期之间的时间差。

–查找当天上午的数据
select * from R_Attendance where (datepart(hour,RDatetime)>=0 and datepart(hour,RDatetime)<12) and datediff(d,RDatetime,GetDate())=0

–查找当天下午的数据
select * from R_Attendance where (datepart(hour,RDatetime)>12 and datepart(hour,RDatetime)<=23) and datediff(d,RDatetime,GetDate())=0

展开全部

相关文章

说两句网友评论
    我要跟贴
    取消