How to use DATEDIFF? How many days are inside two dates

How to use DATEDIFF? How can I make this work? Or should I use DATEDIFF completely differently?

SELECT DATEDIFF('Started ','will_end') AS 'Duration' FROM my_table WHERE id = '110';

I am trying to get an answer how many days are inside two dates.

I would like to receive aswer as:
Duration = 7 days;

I have a database like this:

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

+1
source share
4 answers

Put will_endfirst, startedsecond:

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 reverse windows:

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

NULL? , , 'Started ' 'will_end' DATEDIFF, . , :

SELECT DATEDIFF(Started, will_end) AS Duration FROM my_table WHERE id = '110';

, . , :

SELECT DATEDIFF(will_end, Started) AS Duration FROM my_table WHERE id = '110';
+2

DATEDIFF ( 'will_end', '')

0

, 3 , DATEDIFF (datepart, startdate, enddate)

DATEDIFF (dd, 'Started', 'will_end')

http://msdn.microsoft.com/en-us/library/ms189794.aspx

0

Source: https://habr.com/ru/post/1726337/


All Articles