Refactored form date and to date related logic