views:

244

answers:

1

Hi, I have been looking for a Javascript algorithms that gives me the week number of a given Date object within a custom fiscal year. The fiscal year of my company starts on 1 September and ends on 31 August.

Say today happens to be September 1st and I pass in a newly instanced Date object to this function; I would expect it to return 1.

Hopefully someone will be able to help me with it.

thanks,

fbr

+1  A: 

Say 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

That should do it - maybe there's a problem around new year, but easy enough to figure out I guess.

To get the week number within any year, there are plenty of solutions. Here's just one of them: http://syn.ac/tech/19/get-the-weeknumber-with-javascript/

Seb