Search
 
SCRIPT & CODE EXAMPLE
 

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;
  };
Comment

PREVIOUS NEXT
Code Example
Javascript :: react state value not updating in function 
Javascript :: JavaScript querySelector - By ID 
Javascript :: how to convert string into binary in javascript 
Javascript :: javascript design patterns pdf 
Javascript :: node-json-db 
Javascript :: how to concat nested array in javascript 
Javascript :: accessing via name jquery 
Javascript :: javascript collision detection 
Javascript :: tolowercase js 
Javascript :: javascript lowest number 
Javascript :: localstorage in js 
Javascript :: jwt expiresin 
Javascript :: round number to 2 symbols after comma 
Javascript :: js add function to array 
Javascript :: isfunction javascript 
Javascript :: can we call ajax inside ajax success 
Javascript :: add mute button to html5 video player 
Javascript :: keyup in jquery 
Javascript :: regex check if number is greater than 
Javascript :: javascript Set Intersection Operation 
Javascript :: discord.js get user by username 
Javascript :: css vw not working on mobile 
Javascript :: change inside div with jquery 
Javascript :: javascript sort a b 
Javascript :: parseint 
Javascript :: how to assert in javascript 
Javascript :: docker remove json log 
Javascript :: uuid in node js 
Javascript :: delete from list javascript 
Javascript :: react spring 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =