title: postgresql function timestamp parameter
body: <p>This is my first function.  The select query works well when executed manually fwith fixed constants.  But within my fucntion, the parameters gets wronly interpreted.  </p>
  
  <p>Basically, i'm trying to replace the timestamp with function parameters. </p>
  
  <pre><code>-- this my mananual query.  it works fine.
  select  sum(least(end_time,'2017-05-16 11:30:00')- greatest(start_time,'2017-05-16 10:30:00')) as duration,
      from c_trunk 
      where (start_time &lt; '2017-05-16 11:30:00') and (end_time &gt; '2017-05-16 10:30:00')
      and trunk &lt; 20
  
  -- this is my bogus function with the select that calls it at the end. 
  create function trunk_trafficD (p1 timestamp, p2 timestamp)
      returns boolean as $$
  begin
  select  sum(least(end_time,p2)- greatest(start_time,p1)) as duration,
      count(call_id), device as "system", trunk as "trunk" 
      from c_trunk 
      where (start_time &lt; p2) and (end_time &gt; p1)
      and trunk &lt; 20
      and (device = 1 or device = 4 or device = 3)
  return true;
  end; $$
  language PLPGSQL;
  
  select trunk_trafficD('2017-05-16 10:30:00','2017-05-16 11:30:00');
  </code></pre>