Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stripping dates from something in the WHERE only (not in select)

Status
Not open for further replies.

SyntaxTerror

Technical User
Jan 5, 2011
52
US
We have a report where we allow the user to specify a date range and pull all of the purchase orders pulled between the specified dates.

Well, there is a problem with the report.

The code is like this:
WHERE CreatedDate BETWEEN @begindate AND @enddate

If the begin date is 2011-06-29 and the end date is 2011-06-30, it is ignoring all of the purchase orders made after 2011-06-30 00:00:00, so, 2011-06-30 0:09:52 is being filtered out.

What can I do to strip the time of the CreatedDate values so they pull only the dates?

Thanks in advance!
 
Try


declare @begindate smalldatetime
set @beginDate = '2011-06-09'
declare @enddate smalldatetime
set @endDate = '2011-06-10'

select *
from [TableName]
where convert(varchar, createdDate, 101) between @begindate AND @enddate


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 


Code:
WHERE CreatedDate >= @begindate 
  AND CreatedDate <  @enddate + 1

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
SHIZAM! Exactly what I needed.

+10 style points to you, sir
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top