标签:02 DATEDIFF 01 DateDiff SELECT Sql DiffDate 2008 sever
函数: DATEDIFF(datepart,startdate,enddate)
具体实例:
1 --相差年数 结果0 2 SELECT DATEDIFF(yy,'2008-12-29','2008-12-1') AS DiffDate 3 4 --相差年数 结果1 5 SELECT DATEDIFF(yy,'2008-12-29','2009-12-01') AS DiffDate
1 --相差季度 结果1 2 SELECT DATEDIFF(qq,'2008-02-02','2008-06-30') AS DiffDate 3 4 --相差季度 结果2 5 SELECT DATEDIFF(qq,'2008-02-01','2008-07-01') AS DiffDate
1 2 --相差月 结果4 3 SELECT DATEDIFF(m,'2008-02-02','2008-06-30') AS DiffDate 4 5 --相差月 结果5 6 SELECT DATEDIFF(m,'2008-02-10','2008-07-06') AS DiffDate
1 --相差天数 结果120 2 SELECT DATEDIFF(dy,'2008-03-02','2008-06-30') AS DiffDate 3 4 --相差天数 结果0 5 SELECT DATEDIFF(dy,'2008-02-10','2008-02-10') AS DiffDate
注意:我这里设置了datepart = dy 或者 dd 感觉没啥区别,路过的小伙伴求解答疑惑?
1 --相差小时 结果 20h 2 SELECT DATEDIFF(hh,'2008-03-02 01:01:01','2008-03-02 21:01:01') AS DiffDate 3 4 --相差小时 结果 20h 5 SELECT DATEDIFF(hh,'2008-03-02 01:01:01','2008-03-02 21:59:01') AS DiffDate 6 7 --相差小时 结果 1h 8 SELECT DATEDIFF(hh,'2008-03-02 01:10:01','2008-03-02 02:11:02') AS DiffDate
1 --相差秒数 结果 -10s 2 SELECT DATEDIFF(s,'2008-03-02 10:10:30','2008-03-02 10:10:20') AS DiffDate 3 4 --相差秒数 结果28800s 5 SELECT DATEDIFF(s,'2019-06-04 01:01:01','2019-06-04 09:01:01') AS DiffDate
参考资料:http://www.w3school.com.cn/sql/func_datediff.asp
标签:02,DATEDIFF,01,DateDiff,SELECT,Sql,DiffDate,2008,sever
来源: https://www.cnblogs.com/hanliping/p/10971824.html
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。