Moment JS Get All Dates in Month Example

By Hardik Savani | January 13, 2021 | Category : jQuery


Hi,

I am going to explain you example of moment get all dates in month. step by step explain how to get all dates in a month in moment js. you will learn jquery moment get dates in month. This article will give you simple example of get all dates in month moment js.

Here, i will give you simple example of jquery moment js get all dates in a month.

let's see both example with output:

Example:

<!DOCTYPE html>

<html>

<head>

<title>jquery moment example - ItSolutionStuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>

</head>

<body>

<h1>jquery moment example - ItSolutionStuff.com</h1>

</body>

<script type="text/javascript">

var getDaysOfMonth = function(year, month) {

var monthDate = moment(year+'-'+month, 'YYYY-MM');

var daysInMonth = monthDate.daysInMonth();

var arrDays = [];

while(daysInMonth) {

var current = moment().date(daysInMonth);

arrDays.push(current.format('MM-DD-YYYY'));

daysInMonth--;

}

return arrDays;

};

var dateList = getDaysOfMonth(2021, 01);

console.log(dateList);

</script>

</html>

Output:

0: "01-31-2021"

1: "01-30-2021"

2: "01-29-2021"

3: "01-28-2021"

4: "01-27-2021"

5: "01-26-2021"

6: "01-25-2021"

7: "01-24-2021"

8: "01-23-2021"

9: "01-22-2021"

10: "01-21-2021"

11: "01-20-2021"

...

26: "01-05-2021"

27: "01-04-2021"

28: "01-03-2021"

29: "01-02-2021"

30: "01-01-2021"

I hope it can help you...



Tags : jQuery Moment JS


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: