Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding DATEDIFF()
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01618557
Message ID:
01618568
Views:
30
>I am not sure what are you missing, I am sure missing something as my test works fine:
>
>
>declare @Holiday table ([Name] varchar(32), [Start] datetime, [End] datetime) 
>
>insert into @Holiday ([Name], [Start], [End]) values ('Christmas', '2014-12-24', '2015-12-24')
>insert into @Holiday ([Name], [Start], [End]) values ('New Year', '2014-01-01', '2015-01-01')
>
>SELECT [Holiday].[Name], SUM(DATEDIFF(d, [Holiday].[Start], [Holiday].[End])) from @Holiday Holiday group by [Holiday].[Name]
>
>-- Christmas	365
>-- New Year	365
>
>SELECT [Holiday].[Name], SUM(DATEDIFF(s, [Holiday].[Start], [Holiday].[End])) from @Holiday Holiday group by [Holiday].[Name]
>
>-- Christmas	31536000
>-- New Years	31536000
>
I suspect some dates have time in them and also Michel is using floating math by using 86400.00, for example. Try that for your example.

Interestingly, I can not reproduce the problem myself anymore in my tests although first time I tried I also got incorrect result.

Tried several tests, but it's now working OK for me every time. But I am absolutely sure that earlier today when I first tested I got wrong results.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform