Click here to Skip to main content
15,909,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have got a table named tblEvents from which i need to select all the events between current date and one day behind the current date.I tried the following code but i am not getting events
select *  from tblEvents where (CONVERT(varchar(24),tblEvents.dateEventDate,100)+' '+CONVERT(varchar(20),timeStartTime,100)) between (GETDATE()) and ((GETDATE()-1))


How can i solve this?
Posted
Updated 26-Nov-10 1:11am
v4
Comments
JF2015 26-Nov-10 7:06am    
Editd: Added code formatting.
Manfred Rudolf Bihy 26-Nov-10 7:13am    
In order to help you I'd like to know what the column data types are for dateEventDate and timeStartTime.
deepak thomas 26-Nov-10 7:17am    
dateEventDate-date
timeStartTime-time(7)

Hi,

try this:
select * from tblEvents where (CONVERT(varchar(24),tblEvents.dateEventDate,100)+' '+CONVERT(varchar(20),timeStartTime,100)) between (GETDATE()) and (DATEADD(D,-1,GETDATE()))


Your code is not working, since GetDate returns a DateTime value, this means if you substract 1, you don't substract 1 day!
 
Share this answer
 
v2
Comments
deepak thomas 26-Nov-10 7:07am    
not getting
deepak thomas 26-Nov-10 7:09am    
i tried this
print getdate()

print getdate()-1

and i got the output as

Nov 26 2010 5:37PM
Nov 25 2010 5:37PM

The day is decrementing
Your giving a worng condition in between operatorr

here is my query works fine for me

SQL
select * from dbo.OFFLINE_TRANSACTIONS where dbo.FormatDateTime (CARDUPDATION_DATETIME) between
(getdate()-3) and (GETDATE())



if give reverse in the between query i am not getting any thing

between and (GETDATE()) and (getdate()-3)


First value shuld be grater than second one..
 
Share this answer
 
Comments
deepak thomas 26-Nov-10 7:27am    
thanks very much got output
TweakBird 26-Nov-10 7:29am    
Good call.

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