T-SQL 101: 58 Subtracting dates and times in SQL Server T-SQL using DATEDIFF
When you’re working with T-SQL, it’s common to need to work out how far apart two dates and or times are. Look at the query below:
In this case I’m asking how many days is it from 28th of February 2019 to 31st of July 2019? And if look at the answer:
We can see that it’s 153 days.
Now I used days here but now we could have used any of those other intervals that I discussed when we looked at DATEADD. So I could work at how many minutes that was or how many seconds that was between the two times. I could even say how many months?
2020-02-24