Link to home
Start Free TrialLog in
Avatar of 69stang
69stang

asked on

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))
ASKER CERTIFIED SOLUTION
Avatar of bamboo7431
bamboo7431

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this

SELECT *
FROM DataTable
WHERE JobReleasedDt >= getdate()-2
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