Why is the Danish income 1 day less than the actual difference?
Consider the following piece of SQL code:
Select DATEDIFF(dd, '2014-09-22 09:14:01.850','2014-09-24 17:14:53.243') -- 1
This returns "2", but I really want "3" as I am calculating the total number of days the employee has been working. That is, in the above case, it visited 3 days but datediff
shows 2. Is there a way to get around this?
+3
source to share
2 answers
DATEDIFF with parameter dd
returns the number of date boundaries between two dates.
So, it DATEDIFF(dd, '2014-09-22 09:14:01.850','2014-09-24 17:14:53.243')
will return 2 - because it counts 23 and 24. If you want to count 22, 23 and 24, just add 1, for example.
Select DATEDIFF(dd, '2014-09-22 09:14:01.850','2014-09-24 17:14:53.243') + 1
+4
source to share