Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in below my code

this will showing records of date 08 to 18, don't provide '2017-02-19' records

What I have tried:

SELECT * FROM Bill WHERE 
                     B.Date >= CAST('2017-02-08 12:07:40.330' AS Date)
                     AND
                     B.Date <= CAST('2017-02-19 12:09:13.560' AS Date)
Posted
Updated 8-Feb-17 4:38am
Comments
[no name] 8-Feb-17 10:29am    
"08 to 18, don't provide '2017-02-19' records" and why would you expect it to?

1 solution

Not sure what exactly your intention yet. But if you pay close attention,

CAST('2017-02-19 12:09:13.560' AS Date) return 2017-02-19 (by default the time is
00:00:00.000) and clearly 2017-02-19 00:00:00.000 is not greater than or equal to 2017-02-19 12:09:13.560

This might do the trick.

SQL
SELECT * FROM Bill b WHERE 
                     B.[Date] >= CONVERT(VARCHAR(120), '2017-02-08 12:07:40.330', 120)
                     AND
                     B.[Date] <= CONVERT(VARCHAR(120), '2017-02-19 12:09:13.560', 120) 

Or
SQL
SELECT  * FROM Bill b WHERE 
                     CAST(B.[Date] AS Date) BETWEEN CAST('2017-02-08' AS Date)
                     AND
                     CAST('2017-02-19' AS Date)
 
Share this answer
 
v2
Comments
NIRMAL AJAY 9-Feb-17 1:05am    
it working nicely, thanks bryian

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