如何使用DATEDIFF?两个日期内有多少天 [英] How to use DATEDIFF? How many days are inside of two dates

查看:127
本文介绍了如何使用DATEDIFF?两个日期内有多少天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用DATEDIFF?我如何使这个工作?

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.

我想得到一个aswer像:

Duration = 7天;

I would like to get an aswer like:
Duration = 7 days;

我有这种数据库:

开始| will_end

2009-12-17 | 2009-12-24

2009-12-12 | 2009-12-26

Started | will_end
2009-12-17 | 2009-12-24
2009-12-12 | 2009-12-26

推荐答案

先放入 will_end $ c>开始秒:

Put will_end first, started second:

SELECT  DATEDIFF('2009-12-24', '2009-12-17') 

---
  7

另外,从字段名称中删除单引号:

Also, remove the single quotes from your field names:

SELECT  DATEDIFF(will_end, started) AS Duration
FROM    my_table
WHERE   id = 110

,或将其替换为反引号:

, or replace them with the backticks:

SELECT  DATEDIFF(`will_end`, `started`) AS `Duration`
FROM    `my_table`
WHERE   `id` = 110

这篇关于如何使用DATEDIFF?两个日期内有多少天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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