How to convert the dateDiff() to Decimal

  • 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

  • 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


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply