Im pulling information from a database and ive got the query working fine except i'd like to only select conent from a certain date range. Each row has a field with the created date stored as a DATETIME field. What is the basic syntax?
+2
A:
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'
NullUserException
2010-09-28 02:07:56
Is this formatting style "OMG Ponies" invention or some common convention? ;-)
zerkms
2010-09-28 02:09:48
@zerkms I like how it makes it easier to visualize what you are doing. Yes, I believe I started doing it after seeing one of OMG Ponies' posts.
NullUserException
2010-09-28 02:10:32
the field is a DATETIME field which i believe stores the date as a timestamp in the format YYYY-MM-DD HH-MM-SS but i think the basic syntax will work regardless
Baadier
2010-09-28 02:25:20
+1
A:
WHERE `date_field` BETWEEN '2010-09-21 12:13:14' AND '2010-09-28 12:13:14'
zerkms
2010-09-28 02:08:16
+1
A:
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
Galen
2010-09-28 02:09:11