Manage Learn to apply best practices and optimize your operations.

Formula to compute calendar week

Here is my formula to compute the calendar week number for a given date. This can be very useful in View columns.

Here is my formula to compute the calendar week number for a given date. This can be very useful in View columns.

The rule I am using is: the first week of the year is the week with at least 4 days of the new year. In other words, it is the week, which contains the first Thursday of the year.

REM "First compute week day Mo: 1 till Su: 7, be careful here if your settings are Su: 1 till Sa: 7";
tmpWeekday := 7-@Modulo(8-@Weekday(Datum);7);

REM "Compute Date Offset to Thursday";
tmpOffsetToThursday := tmpWeekday - 4;
REM "the result is a number
between -3 and +3 -> Mo: -3 und Su: +3";
tmpActThursday := @Adjust(Datum; 0; 0; - tmpOffsetToThursday; 0; 0; 0);

REM "Using this offset, compute the date of the corresponding Thursday and the corresponding year -> this gives us the 1.January, to start from, for the computation of the
calendar week";
tmpJan1rstRef := @Date(@Year(tmpActThursday); 1; 1);

REM "Find out the Thursday corresponding to the week of the 1st January computed above.";

tmpOffsetTo1stThu := 7-@Modulo(8-@Weekday(tmpJan1rstRef);7) - 4;
tmp1stThur := @Adjust(tmpJan1rstRef; 0; 0; - tmpOffsetTo1stThu; 0; 0; 0);

REM "If the found Date is in December, then take the date one week after to get the first week of the year.";
@If(@Month(tmp1stThur)=12;@Adjust(tmp1stThur;0;0;7;0;0;0); tmp1stThur));

REM "Now, we have the Thursday of the week we want to get the number from and the first Thursday of the corresponding year. Just subtract the one from the other and convert from Seconds to days and weeks.";
tmpKW := ((tmpActThursday - tmp1stThur) /(24*3600) / 7) + 1;

REM "And here is the contracted version of the code";
tmpActThursday := @Adjust(Datum; 0; 0; @Modulo(8-@Weekday(Datum);7) -
3; 0; 0; 0); tmpJan1rstRef := @Date(@Year(tmpActThursday); 1; 1); tmp1stThur := @Adjust(tmpJan1rstRef; 0; 0; @Modulo(8-@Weekday(tmpJan1rstRef);7)-3; 0; 0; 0); tmpKW := (((tmpActThursday - @If(@Month(tmp1stThur)=12;@Adjust(tmp1stThur;0;0;7;0;0;0); tmp1stThur)) /(24*3600) / 7) + 1); @Text(@Year(tmpJan1rstRef)) + " / " + @If(tmpKW<10;"0";"") +
This was last published in April 2002

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...