Compare Date in select query without time
-
2012년 6월 21일 목요일 오전 2:03
Hello !
I need to pass the StartDate and EndDate into procedure from c#.
I want to compare above date in select query.
How can we just compare date without time ?
for example ,
Tdate is DateTime in sql server , and i am passing DateTime object from .net.
select * from tblHistory where Tdate between @StartDate and @EndDate
Mayur Dabhi
- 편집됨 Mayur Dabhi 2012년 6월 21일 목요일 오전 2:05
모든 응답
-
2012년 6월 21일 목요일 오후 4:53
Are you familiar with date functions (Date and Time Data Types and Functions (Transact-SQL) http://msdn.microsoft.com/en-us/library/ms186724.aspx)?Rick Byham, Microsoft, SQL Server Books Online, Implies no warranty
- 답변으로 제안됨 amber zhangModerator 2012년 6월 22일 금요일 오전 1:51
- 답변으로 표시됨 amber zhangModerator 2012년 6월 27일 수요일 오전 9:35
- 답변으로 표시 취소됨 Mayur Dabhi 2012년 7월 29일 일요일 오전 2:52
-
2012년 7월 29일 일요일 오전 2:52Can anybody give an example ?
Mayur Dabhi
-
2012년 7월 30일 월요일 오전 5:03
Please chek if it works (i dont have sql server now,so cannot check):
Giving two options,I hope one of them will work for you....
SELECT * FROM tblHistory WHERE Tdate BETWEEN datediff(dd,0,@startdate) AND datediff(dd,0,@enddate)
select * from table where datepart(dd,@stardate)>datepart(dd,@enddate) and datepart(mm,@startdate)>datepart(mm,@enddate) and datepart(yy,@stardate)>datepart(yy,@enddate)
cheers!!!
Vatsa
- 편집됨 vatsa_mitr 2012년 7월 30일 월요일 오전 5:07 Added code block
-
2012년 7월 30일 월요일 오전 6:11중재자
Hello,
I have not understood why you have unmarked the reply of Rick Byham 5 weeks after his post. Have you read his post in a full way and especially the link related to the CAST/CONVERT functions ?
http://msdn.microsoft.com/en-us/library/ms187928.aspx
select * from tblHistory where CAST(Tdate AS DATE) between CAST(@StartDate AS DATE) and CAST(@EndDate AS DATE)
i hope i have well copied your piece of code.
Anyway, your thread would be better placed in the TRANSACT-SQL Forum.If you post your agreement, a moderator can move your thread towards the TRANSACT-SQL Forum, no thread to recreate, no lost post and no dying thread in a "bad" forum.
We are waiting for your feedback to try to help you more efficiently.
Don't hesitate to post help or explanations.
Have a nice day
PS : don't forget that the comparision with BETWEEN includes the beginning and ending values
Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

