Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding DATEDIFF()
Message
 
To
16/04/2015 16:01:44
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01618557
Message ID:
01618566
Views:
39
>If I have this:
>
>
>SELECT SUM(DATEDIFF(d,Holiday.Start,Holiday.End))
>
>
>...I can obtain 365.
>
>Now, if I change the type to s, to obtain this same amount in seconds:
>
>
>SELECT SUM(DATEDIFF(s,Holiday.Start,Holiday.End))
>
>
>...I obtain 23533200.
>
>However, If I do 23533200/84600, I do not obtain 365 days but only 272.38.
>
>What am I missing?

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
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform