Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Suppose I have 1,2,3,4,5,6,7,8,9,10 dates data into db. Now I want to show the 8th date data.I have tow date time picker named StartDate, EndDate.
I have use sql quary

SQL
Select * from [table_name] where (received_date BETWEEN @StardDate AND @EndDate)

@StardDate=8th date
@EndDate=8th date

If I use the above code then I found nothing. But if I set

SQL
@StardDate=8th date
@EndDate=9th date

Then I find the result.
Can u explain what is the problem.
Note that: I am using MSSQL205 and ASP.NET(c#)
Posted
Updated 21-Jun-10 7:54am
v2

Check these two date formatting. This may help you to create your query

SQL
SELECT CONVERT(VARCHAR(10), GETDATE(), 102)
SELECT CONVERT(DATETIME, CONVERT(VARCHAR(10), GETDATE(), 102), 102)
 
Share this answer
 
It has to do with the times. Basically, if you say 'between Jun 8 00:00 and Jun 8 00:00 there will never be any results.

Try 'between Jun 8 00:00 and Jun 8 23:59:59' for your expected result.

So, in c# when you create the dates to pass in, initialize the time in the DateTime parameter.

Cheers.
 
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