Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
-
Contact:
Post
by shiznatix »
i want to select between 2 dates. here is what i have right now
Code: Select all
SELECT
id, model_id, image1
FROM
models_info
WHERE
(bday BETWEEN 1980-01-01 AND 2005-01-01)
which does not work. the bday field is stored as DATE. what do i gotta do here kids?
-
trukfixer
- Forum Contributor
- Posts: 174
- Joined: Fri May 21, 2004 3:14 pm
- Location: Miami, Florida, USA
Post
by trukfixer »
Code: Select all
SELECT
id, model_id, image1
FROM
models_info
WHERE
(bday > 1980-01-01 or bday < 2005-01-01);
would seem simpler or...
Code: Select all
where bday < date_sub(curdate(), interval 18 year) and bdate > date_sub(curdate(),interval 25 year);
the above would pick dates where the model (as of the date of the query) is between the age of 18 and 25...
Bri!
-
Burrito
- Spockulator
- Posts: 4715
- Joined: Wed Feb 04, 2004 8:15 pm
- Location: Eden, Utah
Post
by Burrito »
if they are date or datetime fields on the db you need to encapsulate the dates in single quotes.
edit:
here's the query:
Code: Select all
SELECT
id, model_id, image1
FROM
models_info
WHERE
bday BETWEEN '1980-01-01' AND '2005-01-01'