toDateValidation static method

String? toDateValidation({
  1. required String fromDate,
  2. required String toDate,
  3. String? dateFormat,
})

Implementation

static String? toDateValidation(
    {required String fromDate, required String toDate,String? dateFormat}) {
  if (toDate.isEmpty) return "Required";
  if (fromDate.isEmpty) return "Start Date is required";
  if (fromDate.length != 10 || !isValidDate(dateFormat??"MM-dd-yyyy", fromDate)) {
    return "Enter valid start date";
  }
  if (isTodayOrLess(fromDate, dateFormat??"MM-dd-yyyy")!) {
    return "Start date should not exceed end date / today";
  }
  if (toDate.length != 10 || !isValidDate(dateFormat??"MM-dd-yyyy", toDate)) {
    return "Enter valid end date";
  }
  if (!validateDates(fromDate, toDate)) {
    return "End date should be greater than start date.";
  }
  if (isTodayOrLess(toDate,dateFormat??"MM-dd-yyyy")!) {
    return "To date should be less than or equal to today";
  }
  return null;
}