Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Show all dates up to yesterday in SQL Query

Posted on 2015-01-08
4
Medium Priority
?
120 Views
Last Modified: 2015-01-09
I want to show data for all dates up to yesterday at midnight. So I would be excluding any data for today.

Thanks for any assistance.
0
Comment
Question by:srodgers45
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
PortletPaul earned 2000 total points
ID: 40539564
select
*
from sometable
where somedatefield < cast(getdate() as date)
;


or

select
*
from sometable
where somedatefield < dateadd(day, datediff(day,0, getdate() ), 0)
;
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40539654
I agree on the above, see also this article:
http://www.experts-exchange.com/Database/Miscellaneous/A_1499-DATE-and-TIME-don%27t-be-scared-and-do-it-right-the-first-time.html

it's a bit sad that mssql server did implement getdate() as a date+time function, instead (like others) a date() (only date) and now() date + time ...
http://msdn.microsoft.com/en-us/library/ms188383.aspx
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 40539935
Sigh, I utterly agree with you Guy!
But I suspect it came from Sybase (like most of initial mssql) but it's curious they haven't fixed it.
0
 

Author Closing Comment

by:srodgers45
ID: 40540825
Thanks for the help. Much appreciated...
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sourc…
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question