optimization of date comparison