• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

running a SQL query to retrieve current day -2

Guru's,
I have a sql statement list below where I am selecting from a table converting the date to truncate the time. and retrive the data for today,  Now I need to be able to run this select for the current day and also the the prvious 2 days. I would expect that the getdate funtion -2 would be the answer but i am getting spurattic results. Please advice

SELECT *
FROM DataTable
WHERE JobReleasedDt >= Convert(datetime, Convert(varchar, Getdate(), 101))
0
69stang
Asked:
69stang
  • 2
1 Solution
 
bamboo7431Commented:
SELECT *
FROM DataTable
WHERE JobReleasedDt >= Convert(datetime, Convert(varchar, dateadd(day,-2,Getdate()), 101))
0
 
hongjunCommented:
try this

SELECT *
FROM DataTable
WHERE JobReleasedDt >= getdate()-2
0
 
hongjunCommented:
Or if you want to be from time 00:00, then use below

SELECT *
FROM DataTable
WHERE JobReleasedDt >=cast(convert(varchar(11), getdate(), 101) as datetime)-2
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now