Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Last 24hrs data

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2011-03-24 : 07:32:43
Hi all,

I need to select the data entered in last 24 hrs,I tried this today

cst.DateCreated >= dateadd(hour,-24,getdate())and cst.DateCreated <= getdate()

But its not working.it is returning data from 2011-03-22 20:26:06.350 to 2011-03-23 20:24:46.597

I need the data for last 24 hrs, exactly from the time of execution.

An help would be appreciated.

Regards,
SG

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-24 : 07:49:38

cst.DateCreated between DateAdd(day,-1,getdatE()) and getdate()

Cheers
MIK
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2011-03-24 : 07:50:41
if you are trying to pull the data matching the criteria with Date Created column you can just do this
WHERE cst.CreatedDate=DATEADD(HH,-24,GETDATE()).
Go to Top of Page

satheesh
Posting Yak Master

152 Posts

Posted - 2011-03-24 : 08:12:02
sorry both not working

1.cst.DateCreated between DateAdd(day,-1,getdatE()) and getdate()->
returns date from 22-03-2011

and

2.cst.DateCreated between DateAdd(day,-1,getdatE()) and getdate()->
returns nothing

I exactly need last 24hrs data ie.from yesterday same time to the time of execution (today)

Any help would be appreciated..

Regards,
SG

Go to Top of Page

satheesh
Posting Yak Master

152 Posts

Posted - 2011-03-24 : 08:30:10
its starange

cst.DateCreated from cst WHERE cst.DateCreated > dateadd(hh,-9,getdate())

it pulls data around this time yesterday to the time execution now (24hrs) !!
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-24 : 08:42:52
post some sample data you have under the cst.DateCreated column. and both queries which worked and not worked!

Cheers
MIK
Go to Top of Page
   

- Advertisement -