Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a database with a table like:-
C#
ID   Name   Amount   Date
001  abc    200      01/05/2014
001  abc    200      02/05/2014
001  abc    200      03/05/2014
001  abc    200      31/05/2014
001  abc    200      01/06/2014
001  abc    200      02/06/2014


when i am calling data with query
SQL
select * from table_name where Date_ between '01/05/2014' and '31/05/2014'  ORDER BY CONVERT(DateTime, Date_, 103) DESC";

it is showing me extra data of 01/06/2014 and 02/06/204 along with data of date between 01/05/2014 and 31/05/2014

so how to resolve it
i trired
Posted
Updated 4-Sep-14 19:32pm
v3

Hi,

Between means start from that date till that date.

it means that including 01/05/2014 and 31/05/2014

If you want to exclude them then try > and < operator before using be sure there is no Time is attached with your date then it may produce a wrong output.
 
Share this answer
 
Comments
Shantanu sinha 5-Sep-14 1:17am    
txs for reply
select * from expence where CONVERT(DateTime, Date_, 103) >= CONVERT(DateTime, '01/08/2014', 103) and CONVERT(DateTime, Date_, 103) <= CONVERT(DateTime, '31/08/2014', 103) order by Date_ DESC
 
Share this answer
 
Comments
Suvabrata Roy 5-Sep-14 11:19am    
Hi Shantanu,
I am bit worried about your output.
You have always convert values into DateTime ( In don't know why ) for doing that it will not make any format changes.
What Should be your query : I am assuming that Date_ is a dateTime Field

select * from expence where Date_>= CONVERT(DateTime, '01-Aug-2014')
and Date_ <= CONVERT(DateTime, '31-Aug-2014') order by Date_ DESC
SQL
select * from table_name
where 
Date >= '01/05/2014' and Date <= '31/05/2014'
 
Share this answer
 
Comments
Shantanu sinha 5-Sep-14 1:17am    
txs for reply

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