Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding DATEDIFF()
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01618557
Message ID:
01618574
Vues:
32
>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.

From the same sample code I had, if I change it to
SELECT [Holiday].[Name], SUM(DATEDIFF(s, [Holiday].[Start], [Holiday].[End]))/86400.00 from @Holiday Holiday group by [Holiday].[Name]
I've got:
-- Christmas	365.00000000
-- New Year	365.00000000
>
>

Changing one record to have the time portion too:
declare @Holiday table ([Name] varchar(32), [Start] datetime, [End] datetime) 

insert into @Holiday ([Name], [Start], [End]) values ('Christmas', '2014-12-24 06:00:00', '2015-12-24 03:00:00')
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]

SELECT [Holiday].[Name], SUM(DATEDIFF(s, [Holiday].[Start], [Holiday].[End]))/86400.00 from @Holiday Holiday group by [Holiday].[Name]
I've got
-- Christmas	365
-- New Year	365

-- Christmas	364.87500000
-- New Year	365.00000000
Which looks ok to me, but then again, I might be missing Michel point altogether
"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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform