Reputation: 1042
i have dateformate list like this in mysql
--------------------------
born_form | born_to
--------------------------
1994-10-04 | 2012-05-13
1987-05-03 | 2010-03-25
and i have input as 1999 only year
and i m using sql query
Select * from table_name where
"1999" BETWEEN born_from AND born_to
but its not working
Upvotes: 2
Views: 2251
Reputation: 612
I think you can use this,
Select * from table_name where "1999" BETWEEN YEAR(born_from) AND YEAR(born_to)
Upvotes: 0
Reputation: 2318
How about this:
Select * from table_name where
year(born_from)>=1999 AND year(born_to)<=1999
Upvotes: 2
Reputation: 498
here is a example
select * from table_name where year(born_from)>1999 and year(born_to)<=1999
Upvotes: 0
Reputation: 254956
Select * from table_name
where born_to >= '1999-01-01' AND born_from <= '1999-12-31'
This query in comparison to another answers may use indexes
Upvotes: 2
Reputation: 51807
use YEAR()
(see documentation) and do it like this:
SELECT
*
FROM
table_name
WHERE
1999 BETWEEN YEAR(born_from) AND YEAR(born_to)
Upvotes: 8
Reputation: 6202
try with this
Select * from table_name where "1999" BETWEEN YEAR(born_from) AND YEAR(born_to)
Upvotes: 1