Let's say I have a table with two TIMESTAMPTZ
columns - start_time
and end_time
.
In my JS code I'm going to create start and end points using momentjs, and I want to find all the sum of all time differences (end_time - start_time
) for all rows with an end_time
between those two points regardless of the timezone on each individual record.
Normally if all the records in the table are using the same timezone (UTC for example) I would just do something like:
SELECT sum(EXTRACT(epoch from (end_time - start_time) / 3600)) as hours_used FROM table
But I'm unsure of how to accomplish this when different time zones are factored in. Main concern is that I don't want to have a few rows left out by accident because they were in a different time zone than my start/end points.