How to get the first and last day of last month

var nowdays = new Date();

            Var year = nowdays.getFullYear();
            Var month = nowdays.getMonth();
            If(month==0){
                Month = 12;
                Year = year-1;

            }
            If(month<10){
                Month = '0'+month;
            }
            
            Var myDate = new Date(year,month,0);

            Var startDate = year+'-'+month+'-01 00:00:00'; //first day of last month
            Var endDate = year+'-'+month+'-'+myDate.getDate()+' 23:59:00';//Last day of last month