Page 1 of 1

Week of Year

Posted: Tue May 29, 2012 2:26 pm
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);

}

Week of Year

Posted: Thu May 31, 2012 9:07 am
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