如何使用DATEDIFF?两个日期之间有多少天
如何使用DATEDIFF?我怎样才能让它发挥作用?或者我应该完全不同地使用 DATEDIFF 吗?
SELECT DATEDIFF('Started ','will_end') AS 'Duration' FROM my_table WHERE id = '110';
我试图得到答案,两个日期之间有多少天。
我想得到这样的问题:
持续时间 = 7 天;
我有这样的数据库:
开始| will_end
2009-12-17 | 2009-12-24
2009-12-12 | 2009-12-26
How to use DATEDIFF? How can I make this to work? or should I use DATEDIFF completly differently?
SELECT DATEDIFF('Started ','will_end') AS 'Duration' FROM my_table WHERE id = '110';
I try to get answer, how many days are inside of two dates.
I would like to get an aswer like:
Duration = 7 days;
I have this kind of database:
Started | will_end
2009-12-17 | 2009-12-24
2009-12-12 | 2009-12-26
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先放置
will_end
,然后放置started
:另外,从字段名称中删除单引号:
,或将其替换为反引号:
Put
will_end
first,started
second:Also, remove the single quotes from your field names:
, or replace them with the backticks:
您得到的是
NULL
结果吗?您的查询中的列名称包含在单引号中,这意味着您将字符串'Started'
和'will_end'
传递给DATEDIFF
而不是比列值。尝试删除单引号,您将开始看到一些结果:请注意,这会给您带来负面结果。要获得正结果,请颠倒列的顺序:
Are you getting a
NULL
result? You have the column names in single quotes in your query, which means you are passing the strings'Started '
and'will_end'
toDATEDIFF
rather than the column values. Try removing the single quotes, and you will start to see some results:Note that this will give you a negative result. To get a positive result, reverse the order of the columns:
替换订单
DATEDIFF('will_end','Started')
replace the order
DATEDIFF('will_end','Started')
我认为有3个参数需要传入
DATEDIFF ( datepart , startdate , enddate )
所以你的代码将是
DATEDIFF ( dd , '开始','will_end' )
http://msdn. microsoft.com/en-us/library/ms189794.aspx
I think there are 3 parameter to be passed in
DATEDIFF ( datepart , startdate , enddate )
so your code would be
DATEDIFF ( dd , 'Started ','will_end' )
http://msdn.microsoft.com/en-us/library/ms189794.aspx