user3531238
user3531238

Reputation: 51

MySQL: Select all data between range of two dates

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

Answers (5)

user3531238
user3531238

Reputation: 51

Thanks alot, it's working now I was using the wrong enddate.

Upvotes: 0

jmail
jmail

Reputation: 6134

try this:

.. WHERE datum >= '2012-01-01' AND datum <= '2012-12-31'

http://www.sqlfiddle.com/#!2/4b43b/2

Upvotes: 1

Anand Somasekhar
Anand Somasekhar

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

fancyPants
fancyPants

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

Ne Ma
Ne Ma

Reputation: 1709

Use a between statement, for example:

SELECT * FROM applications WHERE datum BETWEEN '2013-11-01' AND '2014-04-01';

You are using a wildcard in your queries, so just figure out what dates you want to use and you are good to rock and roll.

Upvotes: 2

Related Questions