Subtracting dates in SQL

  • I'm trying to subtract the difference in days using two different dates. Example, 01/01/2013 and 08/31/2013. Should be 242 but SQL is showing 426. The data type is smalldatetime. I've also tried converting to CHAR (10) and still have the same problem. Any suggestions?

  • Can you supply the code from your attempt?

    Seems to work fine with this code.

    declare @d1 smalldatetime = '1/1/2013', @d2 smalldatetime = '8/31/2013'

    select datediff(dd,@d1,@d2)

    ______________________________________________________________________________________________
    Forum posting etiquette.[/url] Get your answers faster.

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

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