Calculate working hours between 2 dates in PostgreSQL
According to your question working hours are: Mo–Fr, 08:00–15:00. Rounded results For just two given timestamps Operating on units of 1 hour. Fractions are ignored, therefore not precise but simple: SELECT count(*) AS work_hours FROM generate_series (timestamp ‘2013-06-24 13:30’ , timestamp ‘2013-06-24 15:29’ – interval ‘1h’ , interval ‘1h’) h WHERE EXTRACT(ISODOW FROM h) < … Read more