[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQL Query show items in the last 2 days

Posted on 2015-01-14
3
Medium Priority
?
84 Views
Last Modified: 2015-01-17
How would i do a where clause to show items where the data field is the last 2 days?
0
Comment
Question by:vbnetcoder
[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
3 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40549268
myDateField>=dateadd(day,-2,GETDATE())

will look for any dates which are up to two days ago. So today is Wednesday 5 p.m., so it will look from Monday 5 p.m.

If you wanted to look from Tuesday (so the two days are Tuesday and Wednesday) from midnight, then

myDateField>=dateadd(day,0,datediff(day,0,dateadd(day,-1,GETDATE())))

will do that.

There are shortcuts in SQL Server 2012 and 2014, but the above should work in 2008.
0
 
LVL 15

Expert Comment

by:Deepak Chauhan
ID: 40549337
select * from table1
where CONVERT(varchar(10), dt,101) >= CONVERT(varchar(10), (GETDATE()-2),101)
0
 

Author Closing Comment

by:vbnetcoder
ID: 40555400
ty
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

650 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