Domino Code Fragment

Code Name*
Find the week number for any given date!
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.139.238.76
Description*
Use this formula to find the week number for a date (it follows the same pattern as the Calendar View, with Sunday at the week end day).
Type*
Formula
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

In this example, create a computed field called WeekNo and put this code in it, somewhere on the form after the date field you want to calculate the week number for. Then you need to have a computed year field so that you can sort you view by Year and then Week Number

FIELD WeekNo:=WeekNo;
TempYear := @Year(MyDate);
WeekEndDate := @Adjust(MyDate; 0; 0; @Modulo(8 - @Weekday(MyDate); 7); 0; 0; 0);
YearStartDate := @Date(TempYear; 1; 1);
Week := @Integer(((WeekEndDate - YearStartDate)/86400)/7)+1;
@If(MyDate !=""; @SetField("WeekNo"; @If((Week>52);(Week-52);Week));@SetField("WeekNo"; "No date specified")


To change the week end day, modify the @Modulo formula in WeekEndDate; Monday=7, Sunday=8, etc... Friday=13

This formula also accounts for the week 53 syndrome by making it week 1