Moment JS Get Last Date of Month Example

Moment JS Get Last Date of Month Example

Hello friends,

Today we will show moment js get last date of month. In this example we will explain how to get last date of month in moment js. I would like to share with you get last date of month using moment js.

Here, we will show moment js get first date of month, moment js get last day of month, jQuery moment get last date of month example, how to get last date of month in jQuery moment, moment js startOf() method and endOf() method.

Example

<!DOCTYPE html>
<html>
<head>
    <title>jquery moment example - web-tuts.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 - web-tuts.com</h1>
  
</body>
  
<script type="text/javascript">
  
    var startOfMonth = moment().clone().startOf('month').format('YYYY-MM-DD');
    console.log(startOfMonth);
   
</script>
  
<script type="text/javascript">
  
    var endOfMonth   = moment().clone().endOf('month').format('YYYY-MM-DD');
    console.log(endOfMonth);
  
</script>
  
</html>

Output

2021-01-01
2021-01-31