Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to Check Date Equal to Condition in SQL
example
Table Having Column TradingDate (Datetime DataType)
I want to find a Record where TradingDate='2015-10-05'
the table contain the Tradingdate(ie 2015-10-05 08:10:50) but it is not showing any row

how to check (Trading date contain date as well as time )

select * from Trading where TradingDate='2015-10-05'

please Help
Posted

You should take a look at DATEDIFF.

SQL
WHERE DATEDIFF(dd, TradingDate, '2015-10-05') = 0
 
Share this answer
 
Comments
Sachin MCA2012 15-Mar-15 14:09pm    
is there any other way to compare
=
>=
<= condition
MarbryH 15-Mar-15 22:20pm    
How many methods do you need?

Datediff does all of that in the one call, the relative values being indicated by the return value being <0, =0, or >0.
Because you have time on there as well you have a couple of options.

1. Use BETWEEN
SQL
WHERE TradingDate BETWEEN '2015-10-05' AND '2015-10-05 23:59:59'

Or if you have SQL 2008 or later
2. Convert To Date
SQL
WHERE CONVERT(Date, TradingDate) = '2015-10-05'
which strips off the time.
 
Share this answer
 
Comments
Sachin MCA2012 12-Mar-15 14:18pm    
Yes second option is working
ZurdoDev 12-Mar-15 14:20pm    
Glad to hear it.
Sachin MCA2012 15-Mar-15 14:09pm    
is there any other way to compare
=
>=
<= condition
ZurdoDev 15-Mar-15 16:59pm    
What do you mean?

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