DATEDIFF() returns a value in datepart format, specifying the difference between two specified dates.
Syntax : DATEDIFF ( datepart , startdate , enddate )
Eg:
SELECT OrderID,CustomerID,OrderDate,
DATEDIFF(yy, OrderDate, GETDATE()) YearsPassedSinceOrder
FROM Northwind.dbo.Orders
returns the no. of years passed since the order was placed.
Similarly to find number of months, use 'm' as the datepart or 'd' to determine no. of days.
You can find other values for datepart over here



comments
2 Responses to "Difference between two dates"Thank you for your post.
Thank You Dear ....For your Post
Post a Comment