Added SQL query for date comparison.