Various fixes for date-based queries