Suresh Kumar Suresh Kumar - 1 year ago 70
Node.js Question

Get the week number of the month from week number of the year

I am having a function that is returning the current week of the year like 43,45 etc.

what I want is that to get it as week 1 week 2, for the current month .

P.S I only have current week of the year , Dont have date

Answer Source

Using 'moment' module:

var moment = require('moment');

function foo(weekOfYear) {
    var dayOfMonth = moment().week(weekOfYear).date();
    var weekOfMonth = Math.ceil(dayOfMonth / 7);
    return weekOfMonth;

console.log(foo(1)) //1
console.log(foo(11)) //2
console.log(foo(12)) //3
console.log(foo(13)) //4
console.log(foo(14)) //1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download