July 30, 2010 at 2:59 am
Hi All
I m struggling to convert the dateDiff() to Decimal, because my expected result returns Interger
OK this is my Query
Declare @createdDate datetime
set @createdDate ='2009-06-20'
Select dateDiff(M,@createdDate,Getdate()) OutStandingMonth
--Then My Output OutStandingMonth = 13
--Then I wanted to Convert this Interger value to Decimal like 13.02. meaning 13 Month .02 weeks
July 30, 2010 at 3:14 am
Not really sure what the purpose of something like this is. . . but this should give you what you want.
DECLARE @createdDate DATETIME
DECLARE @months INTEGER
DECLARE @weeks INTEGER
SET @createdDate ='2009-06-20'
SET @months= Datediff(m, @createdDate, Getdate())
SET @weeks= Datediff(ww, ( Getdate() - @months ), Getdate())
SELECT CONVERT(VARCHAR, @months) + '.' + CASE
WHEN @weeks < 10 THEN '0' +
CONVERT(VARCHAR, @weeks)
ELSE CONVERT(VARCHAR, @weeks)
END
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply