Jafer writes "I have 2 fields declared as DATETIME and they store both Date and Time value. Ex: A=2005-08-06 12:08:00.000, B = 2005-08-18 00:30:19.000 I want to find the B-A, considering the time part. When I use the datediff function it considers only the date. I'm looking for a value something like 11.52 days. Is there a direct way to do this or how this can be calculated?"
There are 60 seconds in a Minute, 60 Minutes in a hour, 24 hours in a day - use these values in your query DECLARE @A DATETIME DECLARE @B DATETIME DECLARE @Secs DECIMAL(18, 2)
SET @A = '2005-08-06 12:08:00.000' SET @B = '2005-08-18 00:30:19.000'
Just subtract one from the other and cast to numeric (or decimal or float, etc.)
SELECT CAST(b - a AS numeric(18,2))
FROM (
SELECT
CAST('2005-08-06 12:08:00.000' AS datetime) AS a,
CAST('2005-08-18 00:30:19.000' AS datetime) AS b
) AS A