I want to know the difference in month between 2004-04-16
and 2004-09-30. Im using the datadiff function as
datediff(mm,2004-04-16 ,2004-09-30). The result is 5
month which is correct, but I want to get the remainder
of the days as well. Something like 5.5 days. How can I
get this result?
TIA,
VicRemainder can be difficult...how exaclty do you determine it?
Hopefully this will get you started:
DECLARE @.first varchar(8), @.second varchar(8)
SELECT @.first =3D '20040416'
SELECT @.second =3D '20040930'
SELECT DATEDIFF(mm,@.first ,@.second) AS DateDiff_Months
SELECT DATEDIFF(dd,@.first ,@.second) AS DateDiff_TotalDays
SELECT DATEDIFF(mm,@.first ,@.second) * 30 AS =AverageAmountOfDaysInMonthDiff
SELECT DATEDIFF(dd,@.first ,@.second) - (datediff(mm,@.first ,@.second) * =30) AS Remainder
SELECT DATEPART(dd, @.second) - DATEPART(dd, @.first) AS AnotherRemainder
-- Keith
"Vic" <vduran@.specpro-inc.com> wrote in message =news:1398001c44402$349e4ef0$a501280a@.phx.gbl...
> I want to know the difference in month between 2004-04-16 > and 2004-09-30. Im using the datadiff function as > datediff(mm,2004-04-16 ,2004-09-30). The result is 5 > month which is correct, but I want to get the remainder > of the days as well. Something like 5.5 days. How can I > get this result?
> > TIA,
> Vic
>|||One other thing to note is that DATEDIFF looks at how many 'boundaries' exist between the two dates that you are comparing. So, if you executed DATEDIFF(month, '2004-04-30', '2004-05-02'), the result would be 1, even though there is obviously less than one month in elapsed time between these two dates.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment