Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello experts,

i wrote a query for getting all records between two dates..


but the problem is that i got all records except end(second) date

example---

i wants all records between 22-08-2012 and 5-09-2012

i got records starting from 22-8-2012 to 4-09-2012

so please tell me what to do for getting data of 5-09-2012??????

thanks in advance...
Posted

May be you have stored value in your date column in datetime format
see the difference...
SQL
select case when  '2013-02-07' between '2013-02-05' and '2013-02-07' then 'found' else 'not found' end
--result : found

select case when '2013-02-07 12:9:9 am' between '2013-02-05' and '2013-02-07' then 'found' else 'not found' end
--result : not found

select case when convert(datetime,convert(varchar(10),'2013-02-07 12:9:9 am',103)) between '2013-02-05' and '2013-02-07' then 'found' else 'not found' end
--result : found

so, you should convert datetime value to date like I do in 3rd query...

Happy Coding!
:)
 
Share this answer
 
Comments
fjdiewornncalwe 10-Apr-13 12:59pm    
My 5.
Aarti Meswania 10-Apr-13 13:00pm    
Thank you! :)
 
Share this answer
 
hi ,

VB
AND (CREATEDDATE between @FROMDATE  and  @TODATE)
AND  ( CREATEDDATE <= @TODATE  OR CREATEDDATE >= @FROMDATE)



please try once
 
Share this answer
 
Comments
jayeshkumar.rathod 7-Feb-13 6:04am    
you are right sir...i also applied it..


but now i get my actual query...


i have a provide 5-09-2012 and in my database the records have 5-09-2012 05:33:12 so when the record comparing this record

they are mismatched because it will take 05-09-2012 00:00:00 and compare to 5-09-2012 05:33:12

so do you have a any idea for solving this issue..
Aarti Meswania 7-Feb-13 6:06am    
see second solution apply convert function as I have applied in 3rd query
:)

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