chnet
chnet

Reputation: 2033

php select datetime range

I want to use php to select records from Mysql in date range. for example, i want to select date range ( 2011-02-23, 2011-02-24)

$query = "select * from table where date_field between '2011-02-23' and '2011-02-24'";
mysql_query($query);

It does not work. So, what is the correct format I should use?

Upvotes: 2

Views: 3704

Answers (2)

V-Light
V-Light

Reputation: 3115

$query="select * from table where date_field > '2011-02-23' and date_field < '2011-02-24'";

Upvotes: 0

Kae Verens
Kae Verens

Reputation: 4079

$query="select * from table where date_field >'2011-02-23' "
  ." and date_field<date_add('2011-02-24', interval 1 day)";

Upvotes: 2

Related Questions