Sqlserver
 SQL >> Database >  >> RDS >> Sqlserver

DATEDIFF di SQL Server vs DateDiff di .NET

In realtà l'espressione VB.NET ti restituisce i valori corretti poiché il numero totale di hours non è uguale a 48. Hence restituisce 1

In SQL Server, la funzione DateDiff restituisce un valore arrotondato.

Prova a dividere il valore per il numero totale di secondi in un giorno, che è 86400.0

SELECT @Date1, @Date2, DATEDIFF(ss,@Date1,@Date2) /86400.0 

Il valore restituito sarà 1.9999421 invece di 2

La differenza tra le 2 date in secondi è 172795 che è meno di 172800 (Secondi totali per 2 giorni). Hence la funzione dovrebbe restituire solo 1 se non arrotondi il risultato