Connecting Tech Pros Worldwide Help | Site Map

SELECT yesterdays records

  #1  
Old June 26th, 2009, 12:01 PM
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,063
Provided Answers: 2
I need to do a query something like
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM invoices WHERE date= 'yesterdays date'
It is not as simple as one might think which means ideas I have looked at vary widly.
Could someone please suggest a tidy looking way of doing this.
Not tested below version but there is a cleaner way surely
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM invoices 
  2. WHERE date>=(CAST( FLOOR( CAST( GETDATE() 
  3. AS FLOAT ) ) AS DATETIME ) -1) 
  4. AND date<=(CAST( FLOOR( CAST( GETDATE() 
  5. AS FLOAT ) ) AS DATETIME ))
  #2  
Old June 26th, 2009, 04:59 PM
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,914
Provided Answers: 1

re: SELECT yesterdays records


Will this help?

Good luck!!

--- CK
  #3  
Old June 26th, 2009, 05:45 PM
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,063
Provided Answers: 2

re: SELECT yesterdays records


Will look ar this ck9663.
Probably going to use a generic query with
Expand|Select|Wrap|Line Numbers
  1. WHERE date BETWEEN '$start 00:00:00.000'
  2.         AND '$finish 23:59:59.999'
This being a php application, and pass the same date for yesterday
  #4  
Old June 28th, 2009, 07:25 AM
nbiswas's Avatar
Newbie
 
Join Date: May 2009
Location: India
Posts: 5

re: SELECT yesterdays records


Try this

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM invoices WHERE date=DATEADD(day,-1,getdate())
Hope this helps
  #5  
Old June 29th, 2009, 09:18 AM
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,063
Provided Answers: 2

re: SELECT yesterdays records


Unfortunately this can't work nbiswas because the time element is an integral part of sql server DATETIME.
You can get away with it if all DATETIME time elements are 00.00.0000, but in this case they are not.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to see all the inserted rows of a particular date rohitbasu77 answers 8 March 27th, 2008 06:52 AM
recordset handling question tdr answers 7 May 29th, 2007 08:15 PM