Home Forums SQL Server 2008 SQL Server Newbies Help on Calculation of days between Start & End Date (Including BOTH the Start & End Dates) RE: Help on Calculation of days between Start & End Date (Including BOTH the Start & End Dates)

  • dhananjay.nagarkar (2/14/2014)


    D I wrote a code as below but I'm not sure will it work or not , if not please advice me the right code to accomplish this.

    ------ My code is as below---------------

    Select

    CONVERT(FLOAT,DATEDIFF ( DAY, [Pending].[Req# Target Start Date] ,[Pending].[Temporary Assignment End Date] ) + 1) AS [ORC Position Duration (months)]

    From dbo.pending

    --------------------------

    Thanks

    DJ

    You're the best one to tell if the code works or not. I wouldn't CONVERT to float because it's an aproximate numeric and you are just dealing with integers (there could be a reason to convert it to float but it's not present in the code you posted).

    To make sure the code works, change the column values to well known values so you can make the calculation by yourself and compare it to the result of the query.

    Paraphrasing Nike: Just test it.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2