Martin Scott Consulting | WirelessMail Overview
 

Find the week number for any given date!
Source: [email protected], 04/29/2000
Implementation: Server:
Code Type: FormulaRequired Client:
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).
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