Moment JS

Example of parsing and formatting a Date with Moment JS.

by asha_vyshakh

HTML

<script src="http://momentjs.com/downloads/moment.js"></script>

JavaScript

function getWeekNumber(thisDate) {
var dt = new Date(thisDate);
var thisDay = dt.getDate();

var newDate = dt;
newDate.setDate(1); // first day of month
var digit = newDate.getDay();

var Q = (thisDay + digit) / 7;

var R = (thisDay + digit) % 7;

if (R !== 0) window.alert(Math.ceil(Q)) ;
else window.alert(Q); }

getWeekNumber("08/22/2018");