próximos 7 días en la lista desplegable [duplicado]
Esta pregunta ya tiene una respuesta aquí:
Cómo obtener los próximos siete días desde X y formatear en JS 6 respuestasMe gustaría que los próximos 7 días aparezcan en una lista desplegable. Sin embargo, mi código no parece funcionar.
Tenga en cuenta que el formato de fecha debe seryyyy-mm-dd
.
Me podría ayudar. Aquí está mi código:
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
var curr = new Date;
var first = curr.getDate()
var firstday = (new Date(curr.setDate(first))).toString();
for (var i = 0; i < 7; i++) {
var next = new Date(curr.getTime());
next.setDate(first + i);
options += '<option>' + formatDate((next.toString())) + '</option>';
}
$("#datemenu1").append(options);
$("#datemenu1").html("<option>PICK A DATE</option>");
<html>
<select id="datemenu1">
<option>PICK A DATE</option>
</select>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="Text-1.js"></script>strong text
</html>