Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
select * From Table where Date BETWEEN '23/3/2016' AND '23/3/2016'

What I have tried:

I'm trying to run this query but it gives me the data between two dates and does not show me the data for 1st and last date
Posted
Updated 25-Jul-16 0:51am
Comments
Member 10549697 25-Jul-16 5:21am    
rather i tried 23/3/2016 11:59:59 and it works for me but i dont want to use that

I saw that you found a solution already but I think it is worth to give an explanation on what is happening.

The Date column from your table is probably a DateTime containing date and time. If you use a date without time in your query, the time portion is implicitly set to 00:00:00. So the effective query will be
SQL
select * From Table where Date BETWEEN '23/3/2016 00:00:00' AND '23/3/2016 00:00:00'

This applies also when using a comparison rather BETWEEN.

So there are two common solutions:

Use BETWEEN with time for end date:
SQL
select * From Table where Date BETWEEN '23/3/2016' AND '23/3/2016 23:59:59.999'

Or use less than comparison for the end date with the following day:
SQL
select * From Table where Date >= '23/3/2016' AND Date < '24/3/2016'
 
Share this answer
 
I Have Use this type query for get all result between and also first date and last date

SQL
select * From Table where Date >='23/3/2016' AND  Date <='23/3/2016' 

select * from non_gia_search_history where convert(varchar(10),create_time,110)>='03-15-2016' and convert(varchar(10),create_time,110) <='03-19-2016'
 
Share this answer
 
v2
Comments
Member 10549697 25-Jul-16 5:25am    
Actually i tried this but it works like BETWEEN.so these both methods gives same results
Tushar sangani 25-Jul-16 5:38am    
in date fild date insert like 23/3/2016 or 23/3/2016 00:00:00 ??
Tushar sangani 25-Jul-16 5:49am    
I got this Please check date Formate in Date field is dd/mm/yyyy if not please set it
like

select * from non_gia_search_history where convert(varchar(10),create_time,110)>='03-15-2016' and convert(varchar(10),create_time,110) <='03-19-2016'
Richard Deeming 25-Jul-16 7:37am    
That will prevent the database from using any index on the column to execute the query. It will always have to scan the entire table to find the matching records.

Solution 4 is a much better option.
I found this solution

select * From Table where DATEDIFF(DAY,ColName,23/3/2016) <=0 AND DATEDIFF(DAY,ColName,23/3/2016)>=0
 
Share this answer
 
Comments
Richard Deeming 25-Jul-16 7:36am    
That will prevent the database from using any index on ColName to execute the query. It will always have to scan the entire table to find the matching records.

Solution 4 is a much better option.
select * from Table_Name WHERE myDateTime >= '2008-01-01'
AND myDateTime <= '2008-04-01'
 
Share this answer
 
v2

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