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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to getdata till yesterday upto 11:59PM

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2013-06-04 : 16:23:28
I have a table tab_RM, has data rm_date(datetime)

How to get all data till yesterday upto 11:59PM

select * from tab_RM where rm_date > getdate() -1;

Thanks a lot for the helpful info.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-06-04 : 16:42:29
[code]SELECT * FROM tab_RM WHERE rm_date < CAST(GETDATE() AS DATE);[/code]This will get you everything prior to today.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-05 : 00:07:11
SELECT * FROM tab_RM WHERE rm_date < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)

in case you're on an earlier version as DATE datatype is available only from 2008 onwards

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-06-05 : 08:10:26
quote:
Originally posted by visakh16

SELECT * FROM tab_RM WHERE rm_date < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)

in case you're on an earlier version as DATE datatype is available only from 2008 onwards

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


OP asked the question in SL 2008 forum, so it is not unreasonable to infer that he is using SQL 2008.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-05 : 13:50:31
quote:
Originally posted by James K

quote:
Originally posted by visakh16

SELECT * FROM tab_RM WHERE rm_date < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)

in case you're on an earlier version as DATE datatype is available only from 2008 onwards

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


OP asked the question in SL 2008 forum, so it is not unreasonable to infer that he is using SQL 2008.


that was the hangover from another post. Didnt realize this is on 2008 forum

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -