- How do I calculate the time between two dates in SQL?
- Ask in plain English — 'days between each signup and that customer's first order.' In Postgres, subtracting one timestamp from another gives an `interval`; for a whole-day count nlqdb compiles `EXTRACT(EPOCH FROM (end - start)) / 86400`. It runs the query in Postgres and shows the SQL, so you can confirm which two timestamps it used and the unit.
- Why does EXTRACT(DAY FROM age(...)) give the wrong number of days?
- Because `age(end, start)` returns a month-normalized interval: a 40-day gap comes back as '1 mon 9 days', and `EXTRACT(DAY FROM age(…))` returns only that day component, 9, not 40. Plain subtraction (`end - start`) stays in days, but the count that's robust across any gap is `EXTRACT(EPOCH FROM (end - start)) / 86400`. nlqdb compiles the epoch form and shows it.
- How do I get the average time between two events in SQL?
- Ask for the average directly — 'average time from signup to first order.' In Postgres you can average intervals: `AVG(first_order_at - signed_up_at)` returns an average interval, and dividing the epoch by 86400 gives it in days. nlqdb picks the form from your English and shows the SQL, so the averaged unit is the one you meant.
- Can I compute durations on a Postgres database I already run?
- Yes — connect it with the signed-in BYO connect verb (`nlq db connect`; see /solve/query-existing-postgres-in-natural-language) and ask for the time between your two columns in place, no ETL into a separate store. The honest limits: BYO connect is signed-in only (not the public embed), and the answer is read-only — nlqdb returns the durations, it doesn't write them back to a column.