SQL Datediff在两个日期和返回月份之间 [英] SQL Datediff between two dates and return month

查看:90
本文介绍了SQL Datediff在两个日期和返回月份之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



如果您签入sql请尝试以下查询



选择DATEDIFF(月, '10 / 21/2012','6/1/2013')



它给你8个月,但如果手动计算,天数是223和223/30给出你有7.43



有什么理由吗?



谢谢

巴斯特。

Dear,

If you check in sql try below query

select DATEDIFF(MONTH,'10/21/2012','6/1/2013')

it gives you 8 month but if calculate manually the days is 223 and 223/30 gives you 7.43

Is there any reason?

Thanks
Basit.

推荐答案

查询不询问21月18日到6月1日之间有多少个月。查询询问10月到6月之间有多少个月



如果你想调整天数,那么你必须编写查询来专门做那个
The query is not asking "How many months between 21st oct and 1st Jun. The query asks "how many months between Oct and Jun"

If you want to adjust for days as well then you will have to write the query to do that specifically


Quote:

选择DATEDIFF(月,'10 / 21/2012','6/1/2013')



它给你8个月,但如果手动计算天数是223和223/30给你7.43

select DATEDIFF(MONTH,'10/21/2012','6/1/2013')

it gives you 8 month but if calculate manually the days is 223 and 223/30 gives you 7.43





是的,它是.DateDiff函数你正在使用返回dif几个月,但不是天除以30.请注意,月份的月份不同。一旦它可能是28/29(二月),一次30/31。



Yes, it is. The DateDiff function you're using returns the difference in months, but not days divided by 30. Note that days in month differ between months. Once it could be 28/29 (February), once 30/31.


这篇关于SQL Datediff在两个日期和返回月份之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆