Page 1 of 1

between dates

Posted: Mon Nov 14, 2005 4:11 pm
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?

Posted: Mon Nov 14, 2005 4:16 pm
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!

Posted: Mon Nov 14, 2005 4:18 pm
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'