phone: (540)338-0194
email: ken@kenhamady.com

´╗┐

 Crystal Reports formula examples

Finding the Monday of a selected week (weeks calculated via ISO Standard):

The following formula allows the user to pick a year and a week number, and have the formula calculate the Monday (or any other day) of that week.   In this example, the Year and Week are parameter fields.  The number at the end of the last line determines the day of the week that is returned as the final result.  Since this example ends with a 2, it will return a Monday.   Change it to 1 for Sunday or 7 for Saturday, etc.

WhileReadingRecords;
DateVar target := Date ({?Year},1,1);
    if DayOfWeek (
target) in 2 to 5
    then  
target:= target + 7 * ({?Week}-1) 
    else 
target:= target + 7 * ({?Week}) ;

target - DayOfWeek (target) + 2