Week of Year

Post Reply
foxpalace
Newbie
Posts: 12
Joined: Fri Jan 14, 2011 12:25 pm

Week of Year

Post by foxpalace »

Hi,



I misted some times the function YearOfWeek in Enfocus-Scripting, so i write once for it. Here the result for all of the users:





function jobArrived( s : Switch, job : Job )

{



var DatumAktuell = new Date();

var DieseWoche = "";

var Jan1 = new Date(DatumAktuell.getYear());

var DiesesJahrJan1 = Jan1.setYear ( DatumAktuell.getYear() );



//s.log(1, "Aktuell :" + DatumAktuell);

//s.log(1, "DiesesJahrJan1: " + DiesesJahrJan1);



DiesesJahrJan1 = DiesesJahrJan1.getTime()-(DiesesJahrJan1.getDay()-1)*(24*60*60*1000);

DieseWoche = Math.ceil((DatumAktuell.getTime() - DiesesJahrJan1) / (7*24*60*60*1000))-1;



s.log(1, "Woche: " + DieseWoche);

}
rzacherl
Member
Posts: 36
Joined: Mon Mar 21, 2011 3:29 pm

Week of Year

Post by rzacherl »

Hi foxpalace,



calculating the correct calendar week is quite tricky because officially (at least in Germany) the first calendar week of a year starts with the week which contains the date of 4th of January or in other words the week in which the first Thursday of the year exists.



As a year has 365 or 366 days this means that a year might even start (e.g. if Jan 1st is a Friday or Saturday and its no leapyear) or end with the 1st, 52nd or 53rd calendar week.



There are numerous websites which publish codes in different programming languages for the exact calculation of the year's calendar week.





Regards,



Robert
Post Reply