fix date query function