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
Solved

Show all dates up to yesterday in SQL Query

Posted on 2015-01-08
4
114 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
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 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 48

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
If your app took Google’s lash recently, here are the 5 most likely reasons.
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

856 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