Fixed bug in querying messages in date range