c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
SQL

Datediff Sql Compare two dates

| | SQL

In this article, I will explain how to compare two dates and gets number of days using Datediff in SQL server.

The DATEDIFF() function will return the number of days between two dates.

Syntax:

SELECT DATEDIFF(day,startDate,endDate)

Example:

DECLARE @startDate DATETIME
DECLARE @endDate DATETIME

SET @startDate ='2016-05-15'
SET @endDate ='2016-09-16'


SELECT DATEDIFF(DD, @startDate, @endDate) AS DayDiffrence 

Output: