I was trying to modify a legacy query and come across this code block
select DATEADD(MONTH, DATEDIFF(MONTH, -1,getdate() )-1, 1)
But in my belief the dateadd and datediff function needs some date parameter to do the calculation. But here the DateDiff and DateAdd has some integer values at the place of Date parameter
For example DATEDIFF(MONTH, -1,getdate() )-1 returns 1431 which is just a decimal value, but the code block according documentation looks for Date parameter.
https://www.w3schools.com/sql/func_sqlserver_datediff.asp
Same in the case of DateAdd as well
Someone please share some explanation
w3schoolisw3school- a site with entry level HTML and Javascript tutorials with some SQL databases thrown in. It's not SQL Server's documentation. It's not Mozilla's MDN either - don't expect it to have better docs on the Fetch or File API than MDN. It may be a nice way to find out about the existence of a function, but the actual docs are far better and quite often easier to use. Even google returns the doc sites beforeW3School- Panagiotis KanavosDATEDIFF(MONTH, ...)returns the number of monthes, not years. - Cid