Jquery Moment Get Last Date Of Month Example

Jquery

Nicesnippets

599

05-06-2021


Hi Guys,

In this example,I will learn you how get last date of month in moment js.you can easy and simply get get last date of month in moment js.

Here, i will give you simple example of jquery moment js startOf() method and endOf() method provide you last date and first date of month.

Example:


<!DOCTYPE html>

<html>

<head>

<title>jquery moment example - NiceSnippests.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 - NiceSnippests.com</h1>

</body>

<script type="text/javascript">

var startOfMonth = moment().clone().startOf('month').format('DD-MM-YYYY');

console.log(startOfMonth);

var endOfMonth = moment().clone().endOf('month').format('DD-MM-YYYY');

console.log(endOfMonth);

</script>

</html>

Output:

01-06-2021

30-06-2021

It will help you...