There is a date 2018-11-12 how to take 1 day from it in js? urrDate.setDate(CurrDate.getDate() - 1); it does not work, writes:

 Uncaught TypeError: sdate.getDate is not a function 

    1 answer 1

    The easiest way is through the moment library.

    And if without a library, get the timestamp first and subtract the day in milliseconds from it:

     const dayMilliseconds = 24*60*60*1000; var currentDate = new Date(); currentDate.setTime(currentDate.getTime() - dayMilliseconds); 
    • const dayMilliseconds = 24 * 60 * 60 * 1000; alert (sdate.setTime (sdate.getTime () - dayMilliseconds)); Uncaught TypeError: sdate.getTime is not a function - Pupsik
    • show all code - Undefined
    • Because your sdate is a string, not a date. - Igor
    • Yeah, it works, it only outputs the format 1540000000 and how to convert to the form 2018-11-11? - Pupsik
    • getDate, getMonth, getFullYear methods - Undefined