Here is my query:
SELECT ID AS 'securityid'
, date
, DATEADD(DW, 1, adate) AS 'lagged_date_v2'
, DATEADD(DAY, 1, adate) AS 'lagged_date_v1'
, aclose AS 'previous_close'
FROM mytable
WHERE adate BETWEEN '20170101 09:00' AND '20170630 18:00' AND
ID = 100056;
Here are the output from the code above:
I compared the results to DATEADD
by day and by weekday and it returns the same results.
Column adate
is just typical date, we can tell Jan 28, 2017
is Saturday. However, on this row, both lagged_date_v1
and lagged_date_v2
return Jan 28
. If I use DATEADD
by weekday correctly, I should see Jan 30
instead Jan 28
, right?
My sql server version is 2008.