简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM