Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 0D67C9FA1EB for ; Wed, 5 Sep 2007 00:45:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 38677-10 for ; Wed, 5 Sep 2007 00:45:48 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.180]) by postgresql.org (Postfix) with ESMTP id 3C7599F9EFA for ; Wed, 5 Sep 2007 00:45:48 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id m38so2707698waf for ; Tue, 04 Sep 2007 20:45:47 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; b=oxPj8j/SHZSKpFyA5+HlmR+BJ/+aPq6lIFzOSGYY9J1bBszRUXew7Y7GCl1h1yi9KZ7LcSdPGMPZQMP19JyGHQrXTacwvnA/5D9in6Xlqq8rhwvJgRuoeoyIBwZfHfoxPKI0wn5pIzAOSU0JqAwME15qks1vMWKcnLITH5b7qZQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; b=RoJlWPPWUdPH6NdTZB72rD+eSowqJl6bdaReiT5ASsJmDxW7jsMxexy6v7+DkEecHA1dbBi5C+cpfd+CjEMhDn4HxUynXXrSGNL1jvTW3jVH/Ll3bl1p9uXGU489te+zuhH7taFUlOnMbuoGWm4meFG4CBY36BjtKVqDErydc7s= Received: by 10.114.154.1 with SMTP id b1mr1114411wae.1188963947024; Tue, 04 Sep 2007 20:45:47 -0700 (PDT) Received: by 10.114.81.10 with HTTP; Tue, 4 Sep 2007 20:45:46 -0700 (PDT) Message-ID: Date: Wed, 5 Sep 2007 13:45:46 +1000 From: novice To: pgsql-general@postgresql.org, pgsql-sql@postgresql.org Subject: work hour calculations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: 6edfeb56b2299604 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/128 X-Sequence-Number: 120052 Hello All, SELECT notification_time, finished_time, sum(finished_time - notification_time) as actual FROM log GROUP BY notification_time, finished_time; gives me: notification_time | finished_time | actual ------------------------+------------------------+----------------- 2007-07-06 15:50:00+10 | 2007-07-09 07:10:00+10 | 2 days 15:20:00 2007-07-07 12:30:00+10 | 2007-07-09 07:20:00+10 | 1 day 18:50:00 How can write a query to calculate the duration using custom work hours which is Monday 7am / Friday 5pm? The result I'm expecting for the above to be notification_time | finished_time | actual ------------------------+------------------------+----------------- 2007-07-06 15:50:00+10 | 2007-07-09 07:10:00+10 | 00:20:00 2007-07-07 12:30:00+10 | 2007-07-09 07:20:00+10 | 00:20:00 Thanks.