hi guys,
I have 2 dates. I want to get number of days between 2 dates in storedprocedure.
hi guys,
I have 2 dates. I want to get number of days between 2 dates in storedprocedure.
How about using the dateDiff function ?
eg
DECLARE @Dt INT
SET @Dt = DATEDIFF(dd,@StartDate,@EndDate)
should do the trick ?
Or did I miss something ?
DateDiff function should do what you need
declare @var1 Datetime
declare @var2 Datetime
set @var1 = '2009-04-01'
set @var2 = '2009-04-16'
SELECT datediff(day,@var1, @var2 )
USE tempdb
DECLARE @DATE1 datetime
DECLARE @DATE2 datetime
SET @DATE1 = '01/01/2000'
SET @DATE2 = '02/01/2000'
SELECT DATEDIFF(day, @DATE1, @DATE2)
Note that DATEDIFF only concerns itself with the date portion. If times are involved, a converted subtraction might yield better results.
DECLARE @start DATETIME
DECLARE @end DATETIME
SET @start = '20090514 00:00:00'
SET @end = '20090514 23:59:59'
PRINT CONVERT(FLOAT, (@end-@start)) -- 0.999988
PRINT DATEDIFF(DAY,@start,@end) -- 0