Properly handle dates within queries