简体   繁体   中英

Redshift how to subtract the number of minutes from two different date columns

I would like to subtract two date columns and get the difference in minutes. Based on the table below, we can see that a notification has an ideal_date of 11/29 1pm and we noticed that the actual_date was sent on 12/30 1pm that means that it took 24 hours for the notification to be sent, meaning it took 1440 minutes for the notification to be sent out. I tried the following query but I'm not getting what I need.

select n.ideal_date,
       n.actual_date,
abs(date_part(minute,n.ideal_date) - date_part(minute,n.actual_date)) as minutes
from table_date n
id ideal_date actual_date minutes
58 12/29/2021,1:00pm 12/30/2021, 1:00pm 1440 mins

You want DATEDIFF(). https://docs.aws.amazon.com/redshift/latest/dg/r_DATEDIFF_function.html

select n.ideal_date,
       n.actual_date,
       abs(DATEDIFF(minute,n.ideal_date,n.actual_date)) as minutes
from table_date n

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-2025 STACKOOM.COM