postgresql7.1 and s.completed_datetime >= $start_time and date_trunc('day', s.completed_datetime) <= $end_time