get date range from week number in year


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function getDateRangeOfWeek(weekNo){
  2. var d1 = new Date();
  3. numOfdaysPastSinceLastMonday = eval(d1.getDay()- 1);
  4. d1.setDate(d1.getDate() - numOfdaysPastSinceLastMonday);
  5. var weekNoToday = d1.getWeek();
  6. var weeksInTheFuture = eval( weekNo - weekNoToday );
  7. d1.setDate(d1.getDate() + eval( 7 * weeksInTheFuture ));
  8. var rangeIsFrom = eval(d1.getMonth()+1) +"/" + d1.getDate() + "/" + d1.getFullYear();
  9. d1.setDate(d1.getDate() + 6);
  10. var rangeIsTo = eval(d1.getMonth()+1) +"/" + d1.getDate() + "/" + d1.getFullYear() ;
  11. return rangeIsFrom + " to "+rangeIsTo;
  12. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.