SweetingA
asked on
Problem with datediff in SQL not calculating correctly
SQL Code CAST(DATEDIFF(ss, StartDate, StopDate) AS Numeric(4 , 0))
Result
2014-01-26 15:01:00.000 2014-01-26 15:01:20.000 60
2014-01-26 15:04:50.000 2014-01-26 15:05:00.000 20
Expected
2014-01-26 15:01:00.000 2014-01-26 15:01:20.000 20
2014-01-26 15:04:50.000 2014-01-26 15:05:00.000 10
All ideas most welcome
Result
2014-01-26 15:01:00.000 2014-01-26 15:01:20.000 60
2014-01-26 15:04:50.000 2014-01-26 15:05:00.000 20
Expected
2014-01-26 15:01:00.000 2014-01-26 15:01:20.000 20
2014-01-26 15:04:50.000 2014-01-26 15:05:00.000 10
All ideas most welcome
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hmm. It looks like it had to be that the real difference was, say, 10020, which was then truncated to become 0020 in the final result.
But that would normally cause either an error or a NULL value, depending on your SQL settings.
Is it possible that the actual code and computations might have allowed the value to be truncated that way without causing an error?
But that would normally cause either an error or a NULL value, depending on your SQL settings.
Is it possible that the actual code and computations might have allowed the value to be truncated that way without causing an error?
Open in new window