Javascript algorithm that calculates the week number in the Fiscal Year

I was looking for Javascript algorithms that give me the week number of a given Date object for a selected fiscal year. My company's financial year starts on September 1st and ends on August 31st.

Say today it will be September 1st and I am passing this function to a new Date object; I expect him to return.

Hope someone can help me.

+2


a source to share


1 answer


Suppose you want the fiscal year for date X.

if X > September 1st
  week = week_nr(X) - week_nr(Sept 1st) + 1
else
  // We're in a new year
  week = week_nr(X) + week_nr(Sept 1st) - 1

      



This should do it - maybe a problem around the new year, but simple enough to figure out I think.

There are many solutions to get the week number for any year. Here is just one of them: http://syn.ac/tech/19/get-the-weeknumber-with-javascript/

+1


a source







All Articles