Calculate Date Difference in Sql

To get the difference in date in sql, use the keyword datediff. As of the writing of this article, by providing two sql dates, datediff will return the difference in years, quarter, month, dayofyear, day, week, hour, minute, second, and millisecond.

datediff( datepart, startdate , enddate)

The keyword datediff consists of three parameters. Datepart should be replaced with one of the above bolded keywords. StartDate and EndDate are relatively straightforward.

The MSDN resource can be found at: http://msdn.microsoft.com/en-us/library/aa258269(SQL.80).aspx#

Share and Enjoy:
  • Digg
  • DotNetKicks
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Live
  • MySpace
  • Netvibes
  • Reddit
  • StumbleUpon
You can leave a response, or trackback from your own site.

Leave a Reply