You need to make use of a MySQL number generator to generate the dates series.
Query
SELECT
COUNT(*) AS 'number of days'
FROM (
SELECT
'2015-01-26' + INTERVAL generator.number DAY AS date
FROM (
SELECT
(@number := @number + 1) AS number
FROM (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) AS record_1
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) AS record_2
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) AS record_3
CROSS JOIN (
SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
) AS record_4
CROSS JOIN ( SELECT @number := 0 ) AS init_user_param
) AS generator
) AS dates
WHERE
dates.date BETWEEN '2015-01-26' AND '2016-09-24'
AND
DAY(dates.date) = 27
Result
| number of days |
|----------------|
| 20 |
see demo http://sqlfiddle.com/#!9/c61cdb/9
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…