Retrieve data for a time interval from a DATETIME Column MySQL /PHP
Im pulling information from a database and ive got the query working fine except i'd like to only select conent from a 开发者_JAVA技巧certain date range. Each row has a field with the created date stored as a DATETIME field. What is the basic syntax?
SELECT fields
FROM table
WHERE date BETWEEN '$startDate' AND '$endDate'
Dates in MySQL are in YYYY-MM-DD
format, so the actual query would look like:
SELECT fields
FROM table
WHERE date BETWEEN '2010-10-01' AND '2010-09-25'
WHERE `date_field` BETWEEN '2010-09-21 12:13:14' AND '2010-09-28 12:13:14'
Here's the link
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between
select * from table where datetime between DATE1 and DATE2
SELECT * FROM table
WHERE DateTime
BETWEEN time1 AND time2
精彩评论