Moment JS Get All Dates in Month Example
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Moment JS Get Current Week Start and End Date Example
- Moment Get Current Week Number Example
- Moment JS Get Day Name from Date Example
- Moment Difference Between Two Dates in Hours Minutes and Seconds
- Moment JS Difference Between Two Dates In Years, Months, Days
- Moment JS Humanize Duration | Moment fromNow() Example
- Moment JS Get Last Date of Month Example
- Moment JS Get Month Name from Number Example
- JQuery Moment JS Subtract Hours to Datetime Example
- JQuery Moment Get Current Date Example