Script to get duration
Something like this?

SELECT
  to_timestamp(end_time, 'YYYYMMDDHH24MISS') -
  to_timestamp(start_time, 'YYYYMMDDHH24MISS') as "time_interval"
FROM
  measurement
WHERE
  end_time IS NOT NULL;


There's an sqlfiddle if you want to adjust your question: http://sqlfiddle.com/#!1/576d4/6