calculate time in sql query, easier to undestand; authored by gburton