Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react - min & max for dates

  const disablePastDate = () => {
    let minDate = new Date();
    const today = new Date();

    if (today.getDay() === 0) {
      minDate = minDate.setDate(today.getDate() + 1);
    } else {
      const offset = -27 - today.getDay();
      minDate = minDate.setDate(today.getDate() + offset);
    }

    const convertedDate = new Date(minDate);
    const dd = String(convertedDate.getDate() + 1).padStart(2, "0");
    const mm = String(convertedDate.getMonth() + 1).padStart(2, "0");
    const yyyy = convertedDate.getFullYear();

    return yyyy + "-" + mm + "-" + dd;
  };

  const disableFutureDate = () => {
    var dtToday = new Date();

    var month = dtToday.getMonth() + 1;
    var day = dtToday.getDate();
    var year = dtToday.getFullYear();

    if (month < 10) month = "0" + month.toString();
    if (day < 10) day = "0" + day.toString();

    return year + "-" + month + "-" + day;
  };
 
PREVIOUS NEXT
Tagged: #react #min #max #dates
ADD COMMENT
Topic
Name
9+4 =