how do I calculate a % between dts question

  • I feel stupid + lame asking this - I've been using SQL server for 10 years:

    In this problem there are 3 dates pertaining to a project:

    Start date, Current date, End date. I need to know what

    is the “percent done” (in days) of the project.

     

    Example, if start date = 3/1/07, current date = 3/10/07,

    and end date = 3/31/07, Then “percent done” would be

    about 33.3%. I need to add the ‘%’ at the end too.

     

    I tried this but sqlserver 2005 would not accept it:

      datediff(day, start_date, getdate()) / datediff(day, start_date, end_date)

     

    Please help the lame one...........

     

  • You ar doing integer division, so you will always get 0.  Try this:

    cast(datediff(dd, start_date, getdate()) as decimal)/cast(datediff(dd, start_date, end_date) as decimal)

  • You rock - thanks a bunch - yours was the first one that worked right - sorry re the late reply.

    t

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

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