2012년 6월 21일 목요일 오전 2:03
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 2012년 6월 21일 목요일 오전 2:05
2012년 6월 21일 목요일 오후 4:53Are 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
2012년 7월 29일 일요일 오전 2:52Can anybody give an example ?
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_mitr 2012년 7월 30일 월요일 오전 5:07 Added code block
2012년 7월 30일 월요일 오전 6:11중재자
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 ?
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.