简体   繁体   中英

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

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.

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.

try this:

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

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

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

非常感谢,现在我使用了错误的结束日期,它可以正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM