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:
Post your comments / questions
Recent Article
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
Related Article