SoFunction
Updated on 2025-04-12

How to use Javascript to get dates n days ago


 function Test(day) {
                var today = new Date();
                var beforMilliseconds = () - 1000 * 3600 * 24 * day;
                var beforday = new Date();
                (beforMilliseconds);
                var strYear = ();
                var strDay = ();
                var strMonth = () + 1;
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var strYesterday = strYear + "-" + strMonth + "-" + strDay;
                alert(strYesterday);
            }