Skip to main content

Difference between two dates

Simple case. The difference (in days) between fulfillment and order date:

view: +orders {
dimension: fulfillment_time {
type: string
label: Fulfillment Days
sql: @sql
EXTRACT(isodow from ${fulfillments.created_at}::timestamp)
- EXTRACT(isodow from ${orders.created_at}::timestamp)
;;
}
}

Improved case. The same difference, but with excluding weekends:

view: +orders {
dimension: fulfillment_time {
type: string
label: Fulfillment Days
description: Excluding weekends
sql: @sql (
SELECT count(*)::integer
FROM generate_series(${orders.processed_at}::timestamp, ${fulfillments.created_at}::timestamp, interval '1 day') d
WHERE extract(isodow from d) between 1 and 5
) ;;
}
}