Database time format and SQL query adjustments