February 20, 2007 at 1:49 pm
I have a table with two columns, both of which are dates. What would the script be to subtract one from the other and return just the number of days difference between the two?
Thanks...Nali
February 20, 2007 at 1:55 pm
Checkout the datediff function
February 20, 2007 at 3:05 pm
also the date add function accepts negative numbers, so if you need something like "15 days back from today":
SELECT DATEADD(day, -14, getdate()) AS TwoWeeksAgo
results:
TwoWeeksAgo
------------------------------------------------------
2007-02-06 17:03:39.997
(1 row(s) affected)
Lowell
February 20, 2007 at 11:08 pm
To express the difference between two dates in days...
DATEPART(dd,(DATEDIFF(@startdate,@enddate)))
or
DAY(DATEDIFF((@startdate,@enddate))
Both are equivalent - it follows the SQL tradition of there always being more than one way to solve a problem
February 22, 2007 at 8:57 am
Yeah, both are equivalent: they are both syntax errors.
How about: DATEDIFF(DAY, @startdate, @enddate)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply