You should always use the DATETIME
column format to store dates, not VARCHAR
. You can always deal with presentation issues (e.g. converting to European format) in your application layer. If that was the case you could simply GROUP BY DATE(paid)
i.e.
SELECT COUNT(id), paid
FROM `payments`
WHERE paid IS NOT NULL
GROUP BY DATE(paid)
If your column is VARCHAR
or TEXT
you need to convert it to a value you can group by. If the format is DD-MM-YYYY
, you can simply use LEFT(paid, 10)
to extract the date portion and group by that i.e.
SELECT COUNT(id), paid
FROM `payments`
WHERE paid IS NOT NULL
GROUP BY LEFT(paid, 10)
If you're dates are stored as D-M-YYYY
you will need to convert them using STR_TO_DATE
e.g.
SELECT COUNT(id), paid
FROM `payments`
WHERE paid IS NOT NULL
GROUP BY STR_TO_DATE(paid, '%e-%c-%Y')
Note you can ignore the time portion of the value when converting and so avoid the need for the DATE
function.