user3515460 user3515460 - 7 months ago 13
SQL Question

MySQL Selection Date between

i have this simple mysql code:

SELECT count(avs_id) as gesamtNat FROM sv_erfassung.erfasst WHERE DATUM between '2016-05-01' AND '2016-05-02' and rechtsform = 'natürliche Person';


Mysql gives me zero result. But that can not be as you can see below

enter image description here

But if i trie the following:

SELECT count(avs_id) as gesamtNat FROM sv_erfassung.erfasst WHERE DATUM between '2016-04-29' AND '2016-05-02' and rechtsform = 'natürliche Person';


MySql shows me 24 results.

So whats the Problem?

Answer

You didn't associate time with date try this,

SELECT count(avs_id) as gesamtNat FROM sv_erfassung.erfasst WHERE DATUM between '2016-05-01' AND '2016-05-02 23:59:59' and rechtsform = 'natürliche Person';