modified code for date validation