determining the quantity of dates

Is there a way to calculate the number of a specific day of the week occurring in a month using AngularJS? For example, how can I determine the count of Saturdays in a given month? Thank you. Here is the code snippet I have been working on:

<!doctype html>
<html ng-app="myApp">
<head>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
</head>
<body>

<div ng-app="myApp" ng-controller="myCtrl" ng-init="getdates()">
   <p ng-if="x='Sat'">{{dates.length}}</p>
   <div ng-repeat="x in dates">
    <input type="checkbox" ><p ng-show="x">{{x | format:'ddd'}}</p></input>
  </div>

</div>
  <script>



angular.module('myApp', [])
.controller('myCtrl', function($scope) {
  $scope.dates=[];
  $scope.getdates=function(){
    for(i=0;i<31;i++){
      $scope.myDate = i+' Feb 2015 00:00:00 GMT';
      $scope.dates.push($scope.myDate)
    }
  };

})
.filter('format', function() {
  return function(input, format) {
    return moment(new Date(input)).format(format);
  };
})
;
  </script>

</body>
</html>

Answer №1

Here is a step-by-step guide:

GET/INITIALIZE:

  • Provide the date as an argument
  • Determine the year and month of the input (yearVar, monthVar)
  • Identify the last day of that particular month (last_day_of_month)

NEXT

  • Commence from the first day with

    var currDate = new Date(yearVar, monthVar, 1)

    Locate the first instance of the required day with if(currDate.getDay() == 6) (Sunday is represented by 6)

  • Remember this value, repeat until the day is less than the last day of the month

DATE API Information

Visit: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Setting the initial value of the array to display as a dropdown menu option

I am trying to set the default value of a json array object in a drop down list <select ng-model="selectedItem" ng-options="item as item.taskName for item in abc.taskList" ng-init="selectedItem = selectedItem || abc.taskList[0].taskName"> <pr ...

What is the best method to determine the currency associated with the code in dinero.js?

Is there an easy way to locate the dinero currency in the dinero.js/currencies package using its code? For example, a function called getCurrency that accepts a string as input and outputs the corresponding dinero currency. ...

Errors with pointer events occurring within nested iframes on Chromium 78

At first glance, it seems like a bug specific to Chromium. I have already reported this issue in a bug report. Since progress is slow on that front, I am posting a question here primarily to see if anyone else has encountered similar or related issues and ...

Using Express to Authenticate with the Yelp API

I am currently trying to make a GET request to Yelp's API for a simple search using Express and Node.js, but I am struggling with setting the request header with the provided API key. Despite following the documentation by passing basic authentication ...

Error: The function 'myAppController' is not defined and is therefore not a valid argument

I am trying to incorporate my service into my controller and print a message to the console (in the Auth Service), but I keep encountering this error: Argument 'myAppController' is not a function, got undefined. Can you help me figure out what I& ...

I am struggling to grasp the flow of this code execution

Hi there, I just started my journey in JavaScript learning about two weeks ago. I would really appreciate it if someone could walk me through the execution steps of the code provided below. function sort(nums) { function minIndex(left, right) { ...

Error: Angular does not recognize x2js XML format

I'm attempting to adapt this particular example to utilize xml as json data. However, I am encountering some issues with the code. courses = x2js.xml_str2json(data); console.log(courses.books.course); $scope.todos = courses.books.course; In the XML ...

Issue with the message deletion feature in discord.js

I am encountering an issue with the delete function in discord.js. My code is meant to deduct 1 point from a user's balance when an image is deleted from a channel. The problem arises when I try to delete another image that I uploaded - instead of ded ...

Can you explain the distinction between document.body.ononline and navigator.onLine?

Can you explain the distinction between document.body.ononline and navigator.onLine? Do they utilize the same JavaScript API for checking network connectivity status (online/offline)? I have searched on Google but couldn't find a definitive answer. If ...

Adjusting the outline color of a Material UI Select component in outlined mode to a different color when the dropdown is activated (currently shown as blue)

Is there a way to change the outline color of Material-UI select component outlined variant correctly? I need help changing the default blue color to red, any assistance would be greatly appreciated Click here for an image reference Reference code snippe ...

Retrieve the store location value when clicked (Javascript)

I'm currently struggling to capture the value of a click in my Javascript code and I could use some help understanding how to achieve this. <span class="s-link"> <a class="s-link-pim-data" href="javascript:void(0);" target="_blank" title="O ...

Let's explore further - delving into JSON & array manipulation using the foreach loop in Pure JavaScript

Although I have some experience with Java Script, I still consider myself a beginner in certain areas, particularly when it comes to accessing JSON objects and arrays. I've tried various syntax and options for accessing arrays using [], but so far, I ...

What could be the reason behind the unexpected outcome of process.argv[3] when its value is set to '*'?

My calculator app is very straightforward: if (process.argv[3]==='+') console.log(parseInt(process.argv[2]) + parseInt(process.argv[4])); if (process.argv[3]==='-') console.log(parseInt(process.argv[2]) - parseInt(process.argv[4])); i ...

Ensuring jQuery filter() works seamlessly with Internet Explorer versions 6, 7, and 8

On my webpage, I have implemented an ajax call using the jQuery library to handle a specific task. After making the ajax call, I need to parse the response message that is returned. However, I encountered an issue with Internet Explorer versions 6, 7, and ...

The error encountered with react createRef was caused by a faulty implementation

Here is the revised question post completing the answer In this particular code snippet, I have encountered an issue where my file browser opens correctly upon submission, however, the updated state is not reflected when I click the final submit button. ...

What could be causing Next.js to throw an error upon completion of the MSAL OAuth process?

I encountered an error while building a website using next.js. The site is set up for production, and after the authentication process with MSAL for Azure AD integration, I am facing the below error during the OAuth loop. As a beginner in next.js coming fr ...

The process of incorporating user properties into the output of a Service Bus topic from a Javascript Azure Function

I'm currently developing a TypeScript Azure Function that utilizes an Azure Service Bus topic as its output. Although I am able to send messages successfully, I have encountered difficulties in setting custom metadata properties for the message. In m ...

Calling a function within another function

In my code, I have a function that formats the price and retrieves the value needed for refactoring after upgrading our dependencies. I'm struggling with passing the form value to the amountOnBlur function because the blur function in the dependencie ...

Unable to interact with web element using JavaScript

Struggling to find a solution for simulating a click on a button element on Outlook.com mobile website using JavaScript. Despite numerous attempts from online sources, the button remains unresponsive to clicks. An interesting discovery was made that the c ...

Experiencing problems with integrating Slim framework and AngularJS, such as encountering a 404 error

Although this may seem like a repeat question, I am encountering an issue with using AngularJS with Slim Framework web services. I have set up a webservice to retrieve a student record with a URL structure like: http://www.slim.local/api/getstudent/1 ...