Skip to content

Instantly share code, notes, and snippets.

@cdiaz
Last active September 16, 2016 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdiaz/fb0e39ffaf7485a6cb2aae1d1d61ae2f to your computer and use it in GitHub Desktop.
Save cdiaz/fb0e39ffaf7485a6cb2aae1d1d61ae2f to your computer and use it in GitHub Desktop.
Obtener los proximos 7 dias a partir del dia actual
function getweek(curr) {
if (curr instanceof Date){
curr.setDate(curr.getDate()-1);
var week=[];
for(var i = 0; i<7; i++) {
week.push({[i]:[getday(new Date( curr.setDate(curr.getDate() + 1)))]});
}
return week;
} else {
return("Debe enviar una fecha valida")}
}
function getday(date){
var months = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Juio", "Agosto","Septiembre","Octubre", "Noviembre", "Diciembre");
var days = new Array("Dom","Lun","Mar","Mie","Jue","Vie","Sab");
var curr_date = ("0" + date.getDate()).slice(-2);
var curr_month = date.getMonth();
var curr_year = date.getFullYear();
var day = days[date.getDay()];
return(JSON.stringify({dayname: day , daynumber:curr_date, monthname : months[curr_month], year: curr_year}));
}
console.log(getweek(new Date()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment