Search code examples
javascriptdatedatetimeprototypejsmomentjs

Change the start of the year in moment.js


I am using momentJS for date calculations.

Here I want to change start of year for weeks calculation.

For me start of year will be 1-nov and end will be 31-oct.

or any other JS date lib that allows me to do the same.


Solution

  • Try this out:- http://jsfiddle.net/EvLmF/

    var EndDate = moment([2008, 0, 29]);//End Date
    var StartDate = moment([2007, 0, 28]);//Start Date
    
    alert("Weeks : " + EndDate.diff(StartDate, 'weeks'));
    alert("Days : " + EndDate.diff(StartDate, 'days'));
    alert("Years : " + EndDate.diff(StartDate, 'years'));
    

    So create new moment objects with your start date and end date and perform operations as required.