Difference B/W Two Dates In SQL: What Are The Different Methods?

Asked By 0 points N/A Posted on -
qa-featured

I am doing a project related to SQL. I am stuck with the problem of how to find the difference between two dates in SQL. Which commands to use?

SHARE
Answered By 10 points N/A #85780

Difference B/W Two Dates In SQL: What Are The Different Methods?

qa-featured

The DATEDIFF() returns the difference between two dates in SQL.

Syntax:

DATEDIFF(depart, start date, end date)

Example:

SELECT DATEDIFF(day, '2016-05-05', '2016-07-05') AS DiffDate

Result:

DiffDate

61

This syntax yielded result in positive. In this syntax, the first date is earlier than the second date.

Syntax:

DATEDIFF(depart, end date, start date)

Example:

SELECT DATEDIFF(day, '2016-07-05', '2016-05-05') AS DiffDate

Result:

DiffDate

-61

This syntax yielded result in negative. In this syntax, the first date is afterward that of the second date.

Login/Register to Answer

Related Questions