Added checks for invalid date inputs