Friday, 15 May 2015

jquery - How do I calculate number of given weekday between range using Moment JS? -


I have found out how many days of the day (eg: Tuesday), the date range using js and jquery Are you in

I can find the number of days using the difference:

And I know the beginning and end date, so I think it should be possible?

Example: How many Tuesdays are from March 1 to March 25?

I came up with the following function that I have tried to work for a handful of test cases Seems to:

  between work days of week (d1, d2, isoWeekday) {// We have a valid moment example D1 = moment (D1); D2 = Moment (D2); // The next day to decide how many days should be detected (0 if D1 is already a day of specified day) to advance in advance for specific day. Var for days = ((7 + isededed) - D1. ISOUpdate ())% 7; Var Next Today Day = d1.clone (). Add (daysToAdd, 'days'); // If we have already passed the last date, then it should not be at any time of the day. If (next to date SISF (D2)) {return 0; } // Otherwise, just return the full number of weeks / difference and for one day, which we are already upgrading for several weeks = D2 Diff (next day, 'week'); Between return weeks + 1; }  

On the day you are trying to count, you have gone through the value. Like for Tuesday, pass in 2 .

Sample charge:

  var d1 = moment ('2015-03-01'); Var d2 = moment ('2015-03-25'); Console.log ('Result:', in weekdays (D1, D2, 2)); // = & gt; Result: 4  

.


No comments:

Post a Comment