Hello All,
I am utilizing moment.js to do take care of some times and dates in a time sheet form. I want to automatically calculate the dates for a full week based upon input from the user. I have the following to preform the calculations. It works accept for one thing: it uses today's date instead of the date the user selects which is .weekEndingDate I believe the issue lies in the way I am declaring and assigning the value to lastDayOfWeek. If it helps, the date will print out in the following format if no formatting is applied to it: Mon Oct 30 2017 15:47:55 GMT-0400 Any suggestions would be greatly appreciated.
function findDates() { var calcDay; var formatDate; lastDayOfWeek = moment($(this).find('.weekEndingDate input').val()); // get last day of week and set as moment item formatDate = lastDayOfWeek.format('MM' + '/'+ 'DD' + '/'+ 'YYYY'); // format date for display $('.weeklyTimesTable tbody tr:nth-child(' + 7 +')').find('.date input').val(lastDayOfWeek); do { calcDay = lastDayOfWeek.subtract(1, 'days'); // calculate days in decsending order formatDate = calcDay.format('MM' + '/'+ 'DD' + '/'+ 'YYYY'); // format date for display $('.weeklyTimesTable tbody tr:nth-child(' + weekDayCount +')').find('.date input').val(formatDate); weekDayCount--; } while (weekDayCount >= 1); } //end findDates