Trent Bourne
Trent Bourne

Reputation: 1

Postgres Hours Calculation

I have been trying to work this out all week. I have a table with values names start and finish. I need a Postgres query to relay the hours back to me in a nice format.

The original (before hours) query is this

select * from public.volass
where linkedass=$request_id 
order by start

So when I try and use DiffDate I make it look like

select datediff(hours,start,finish), * from public.volass
where linkedass=$request_id 
order by start

Postgres then gives me the following error.

ERROR:  column "hours" does not exist
LINE 1: select datediff(hours,start,finish), * from public.volass
                        ^
********** Error **********
ERROR: column "hours" does not exist
SQL state: 42703
Character: 17
  1. Do I need to have a field named "Hours" in the system for this to work
  2. Even if I add a field named "hours" it still stuffs up
  3. Can you steer me in the correct direction to use Difdate

Upvotes: 0

Views: 102

Answers (1)

Parfait
Parfait

Reputation: 107767

Consider using Postgre's EXTRACT:

SELECT (EXTRACT(EPOCH FROM finish - start) / 3600) AS duration, *
FROM public.volass 
WHERE linkedass=$request_id 
ORDER BY start

Upvotes: 1

Related Questions