Click here to Skip to main content
15,860,972 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi to all,
I need To check TWo Datetime Field wiht current datetime in sql select Query.

Here i have Two Fields From_date, To_date DATATYPE datetime. I need To check This Field With current system Datetime.

NOTe:
I need to search DATE And TIME.

What I have tried:

select c.Offername as Definition,Offerid as stockid,CAST('0' AS MONEY)
as Available_QTY,c.categoryid from tbloffer as c where
from_time >= getdate() and to_time<=getdate()
Posted
Updated 4-Oct-16 21:59pm
v2
Comments
Thanks7872 5-Oct-16 2:37am    
And what is the question?

1 solution

In common sense, from_datetime should be before to_datetime, your code defies this:
from_time >= getdate() and to_time<=getdate()

re-examine your logic.
In fact, you can simply do this:
SELECT * FROM tablename WHERE getdate() BETWEEN from_datetime AND to_datetime
 
Share this answer
 
Comments
JonPoley3 5-Oct-16 5:24am    
That's the type of bug you can stare at yourself for hours but is completely obvious to everyone else in seconds.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900