Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my database i have a table which has a datetime field
when i am inserting data it is including time with date
i am facing problem in selecting the data of any specific
date
Say date1 between '08/01/2014' and '08/01/2014'
my query is

SQL
SELECT *, (case when entrytype=0 or entrytype=3 then amount else 0 end )as Dmt
,(case when entrytype=1 or entrytype=2  or entrytype=4 or entrytype=66
 then amount else 0  end )as cmt FROM FeesLedger
 WHERE EntryDate
 BETWEEN '01/08/2014' AND '01/08/2014' 
AND StudentId = 2 AND Amount > 0 ORDER BY EntryDate,EntryNumber
Posted
Updated 7-Jan-14 19:37pm
v2
Comments
Maciej Los 8-Jan-14 1:46am    
What kind of problem? Query looks OK.
srilekhamenon 8-Jan-14 2:28am    
it is not returning any result
srilekhamenon 8-Jan-14 2:30am    
is it depend upon our system date format my system format dd/mm/yyyy

First of all, please, read my comment to the question.

Have a look at your WHERE statement:
SQL
WHERE EntryDate BETWEEN '01/08/2014' AND '01/08/2014' 

2 things:
1) year is equal 2014. Is it correct?
2) If you want to fetch data for single date, use:
SQL
WHERE EntryDate = '01/08/2014'


Sometimes, you need to change date format using SET DATEFORMAT[^] command to properly fetch data.
SQL
SET DATEFORMAT mdy;  --for other parameters, see the documentation
SELECT ...
FROM ...
WHERE datefield = '01/08/2013'
 
Share this answer
 
try changing this:
SQL
BETWEEN '2014/01/01' AND '2014/01/07'
 
Share this answer
 
This should work
C#
BETWEEN '01 Jan 2014' AND '07 Jan 2014'
 
Share this answer
 
Try changing the date format:
SQL
SELECT *, (case when entrytype=0 or entrytype=3 then amount else 0 end )as Dmt
,(case when entrytype=1 or entrytype=2  or entrytype=4 or entrytype=66
 then amount else 0  end )as cmt FROM FeesLedger
 WHERE EntryDate
 BETWEEN '2014-01-08' AND '2014-02-08' 
AND StudentId = 2 AND Amount > 0 ORDER BY EntryDate,EntryNumber
ISO format is SQL default, and it may be that the system the SQL Server is running in is set to US format dates.
 
Share this answer
 
Hi,

I have used this type of query many time I hope this help full you.
try this
SQL
where Post_date between CONVERT(date,first Date) and CONVERT(date,second date)

for any query free help hit to reply.
Happy coding ☺
jsb
 
Share this answer
 

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