'Date filter in sql query to get today value

I want a link from data table where logo link is <= fromdate and >= todate.

I' writing this query to get value

select *  from getlogo 

select * from getlogo 
where (Convert(date,logofrom) >= getdate()) and (Convert(date,logoto) <= getdate()) 
and active=0


 today = 03/25/2015
 from = database.value logofrom 
 to = database.value logoto     
 how to compare this and get value 

Result:

enter image description here



Solution 1:[1]

If you want the logo that has a date range in which today falls then reverse the conditions:

(Convert(date,logofrom) <= getdate()) and (Convert(date,logoto) >= getdate()) 

This would return the logo with id = 2 in your example.

Solution 2:[2]

You should CAST GetDate in order to include dates on edges:

SELECT  *
FROM    getlogo
WHERE   CAST(logofrom AS DATE) <= CAST(GETDATE() AS DATE)
        AND CAST(logoto AS DATE) >= CAST(GETDATE() AS DATE)
        AND active = 0

Solution 3:[3]

If by your description, you need the second record as result..

use this query

select * from getlogo where getdate() between convert(datetime,logofrom) 
and convert(datetime,logoto) and  active=0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jpw
Solution 2 Giorgi Nakeuri
Solution 3 Sunil Acharya