Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var from = new Date(2014, 3, 11);
- var to = new Date(2014, 3, 13);
- var DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
- var d = from;
- while (d <= to) {
- alert(DAYS[d.getDay()]);
- d = new Date(d.getTime() + (24 * 60 * 60 * 1000));
- }
- function days(from, to) {
- var d = new Date(from),
- a = [],
- y = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
- while (d < to) {
- a.push(y[d.getDay()]);
- d.setDate(d.getDate() + 1);
- }
- if (d.getDay() === to.getDay()) // include last day
- a.push(y[d.getDay()]);
- return a;
- }
- // ex. usage
- var from = new Date(2014, 4 - 1, 11),
- to = new Date(2014, 4 - 1, 13);
- days(from, to); // ["Friday", "Saturday", "Sunday"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement