Reputation: 51
How do I make a query that select everything between two dates.
SELECT * FROM applications WHERE `datum` >='2013-11%' AND `datum`<='2014-04%';
I was trying to do something like that but that doesn't work that only returns one record.
Can someone show me how to make it show everything between a range of two dates.
Datum's type is Datetime.
like 2013-11-02 12:21:00
Upvotes: 2
Views: 1671
Reputation: 6134
try this:
.. WHERE datum >= '2012-01-01' AND datum <= '2012-12-31'
http://www.sqlfiddle.com/#!2/4b43b/2
Upvotes: 1
Reputation: 596
Try this one
$query="SELECT * FROM applications WHERE `datum` between '2013-11-01' AND '2014-04-01'";
or
$query="SELECT * FROM applications WHERE `datum` WHERE `datum` >= '2013-11-01' and `datum` <= '2014-04-01' ";
both are working
Upvotes: 0
Reputation: 51868
The %
is used in like
searches, which applies to (var)char and text columns.
SELECT * FROM applications WHERE `datum` >='2013-11-01' AND `datum`<='2014-04-31 23:59:59';
In MySQL it's safe to use 31 as the upper end of a month, even for february.
Upvotes: 1