01-Mar-2021
.
Admin
Hi Dev,
In this article, I would like to share with you example of moment get all dates in month. I will explain you how to get all dates in a month in moment js. We 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. So let's see bellow example with output:
Example:
<!DOCTYPE html>
<html>
<head>
<title>jquery moment example - NiceSnippets.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 - NiceSnippets.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: "02-31-2021"
1: "02-30-2021"
2: "02-29-2021"
3: "02-28-2021"
4: "02-27-2021"
5: "02-26-2021"
6: "02-25-2021"
7: "02-24-2021"
8: "02-23-2021"
9: "02-22-2021"
10: "02-21-2021"
11: "02-20-2021"
...
26: "02-05-2021"
27: "02-04-2021"
28: "02-03-2021"
29: "02-02-2021"
30: "02-01-2021"
It will help you....
#Jquery