Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. var from = new Date(2014, 3, 11);
  2. var to = new Date(2014, 3, 13);
  3. var DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  4.  
  5. var d = from;
  6. while (d <= to) {
  7. alert(DAYS[d.getDay()]);
  8. d = new Date(d.getTime() + (24 * 60 * 60 * 1000));
  9. }
  10.  
  11. function days(from, to) {
  12. var d = new Date(from),
  13. a = [],
  14. y = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  15. while (d < to) {
  16. a.push(y[d.getDay()]);
  17. d.setDate(d.getDate() + 1);
  18. }
  19. if (d.getDay() === to.getDay()) // include last day
  20. a.push(y[d.getDay()]);
  21. return a;
  22. }
  23.  
  24. // ex. usage
  25. var from = new Date(2014, 4 - 1, 11),
  26. to = new Date(2014, 4 - 1, 13);
  27. days(from, to); // ["Friday", "Saturday", "Sunday"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement