0

How should I achieve listing all saturdays and sundays between two dates into a listbox or textarea in Angular JS date picker on a button click and save them on another screen as Weekend under holiday name and the list of dates under holiday date? I'm trying to display all the holidays list of records with column holiday name as weekend and dates for all the saturdays and sundays as below. I will be entering the holiday name in the text box and click on the Weekend button to get all the dates of saturdays and sundays and save changes to store the multiple list of records.

Holiday Name Holiday Date

Weekend 25-07-2015

Weekend 26-07-2015

...

Community
  • 1
  • 1
Don
  • 102
  • 1
  • 10

1 Answers1

0

Getting the weekends is relatively straightforward using a while loop and incrementing the active day:

  $scope.start=new Date(2015,6,1);
  $scope.end= new Date(2015,8,1);
  $scope.weekends = [];

  var day = angular.copy($scope.start);
  while(day < $scope.end){        
     var d = day.getDay(); 
     if(d === 0 || d === 6){
       $scope.weekends.push(new Date(day));
     }
     day.setDate(day.getDate()+1);
  }

Change to <= if you want to include last day.

You would need a list of holidays and their dates for whatever locale the user is in to generate that list from within the same loop

DEMO

charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • Charlie, I need to be able to delete the working saturdays from the holidays list from the list box and add the individual week days into the list as well from the date picker also. – Don Jul 27 '15 at 14:51
  • This isn't very clear...you asked for a list of weekend days ...which is what was provided in answer . Please create a demo in [plunker](http://plnkr.co/edit/?p=catalogue) that gives a better idea of what you are trying to accomplish. I only provided you what question asked..how to get weekend days list – charlietfl Jul 27 '15 at 15:05
  • So where is the problem in deleting them? How? user event? filter? deleting items from array isn't difficult see: http://stackoverflow.com/questions/15453979/how-do-i-delete-an-item-or-object-from-an-array-using-ng-click/15454424#15454424 – charlietfl Jul 27 '15 at 15:32
  • You are essentially creating a whole new question that is different than what was interpreted from this question. I suggest you accept this one and start a whole new question that better outlines what you are now trying to do...the problems you are having doing it...and the expected results Include your code and the demo in new question – charlietfl Jul 27 '15 at 15:52
  • Charlie, is there any way that we can add a weekday Mon - Fri also into this holiday list from a datepicker – Don Jul 30 '15 at 04:02
  • Sure... can push whatever you want into an existing array – charlietfl Jul 30 '15 at 12:37