# Assumes the time is coming in as 12:47:02 sub get_pressure { my ($data_time) = @_; my $sql = <<__END_SQL__; SELECT weather_time ,baro_pressure FROM pressure WHERE weather_time < TO_DATE(?, 'HH:MI:SS') ORDER BY weather_time DESC __END_SQL__ my $sth = $dbh->prepare($sql) || die ... $sth->execute($data_time) || die ... $sth->bind_columns(\my ($press_time, $pressure)); # You only want the first column returned. $sth->fetch; return $pressure; }