Javascript

Get current week first date & last date in moment js

Get current week first date & last date in moment js.

<html>
  <body>
     <div id="abc"></div>
     
     <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.js"></script>
     <script type="text/javascript">
	  function getStartAndLastDateOfThisWeek(){
	      var startOfWeek = moment().startOf('isoWeek');
	      var endOfWeek = moment().endOf('isoWeek');

	      return "<div class='xyz'>" + startOfWeek.format('DD') + " - " + endOfWeek.format('DD MMM') + ", " + moment().format('YYYY') + "</div>";
	  }
	
	  document.getElementById("abc").innerHTML = getStartAndLastDateOfThisWeek();
      </script>
   </body>
</html>

The output is 03 – 09 Sep, 2018 based on posting date.

Fool Dev

I didn't get trained by the school system like other kids, and when I did concentrate on learning, my mind was cluttered and locked by the programming of the system. © Huey Newton