Thennarasu
Thennarasu

Reputation: 474

how to Difference between two date SQL server

how to find difference between two date . in database i have two columns transaction date and submitted Date . how to find how long to take to submit after transaction date approved

Employee   transaction Date      Submit date 
Kenya        01-06-2019          22-06-2019
Sandy        02-07-2019          15-07-2019

but i want get how long to take submit after transaction date

   Employee   transaction Date      Submit date     difference Date
    Kenya        01-06-2019          22-06-2019      21 days 
    Sandy        02-07-2019          15-07-2019      13 days 

how to find this ? any one help me ?

Upvotes: 0

Views: 65

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521249

Use DATEDIFF:

SELECT
    Employee,
    transaction_date,
    submit_date,
    DATEDIFF(day, transaction_date, submit_date) AS difference
FROM yourTable;

If you want the literal output you showed us, then use:

CAST(DATEDIFF(day, transaction_date, submit_date) AS varchar(max)) + ' days' AS difference

Upvotes: 3

Related Questions