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



 Crystal Reports formula examples

How to Find the First Friday of a Month (or any other weekday):

The following formula will allow you to find the first Friday of a month, based on any input date that you provide.  Your input date can be a database field, a formula, a parameter field or even the function CurrentDate.  The Input Date goes on the second line, in place of "currentdate".   You can also change the formula to find another day of the week by changing the number 6 on the third line to any number from 1 to 7.  Use 1 for Sunday and 7 for Saturday, etc.   The fourth line allows you to set the week.  The 1 means to return the first Friday of the current month.

  WhileReadingRecords;
 DateVar D:= currentdate;  //Today's Date or any date field
 Numbervar DOW:= 6; //The day of week you want with 1 being Sunday, 2 = Monday, etc
 NumberVar Week:= 1; // The Week you want, 1 being the FIRST Monday of the month, 2 being the second, etc
 DateVar BOM:= D - Day(D)+(8-DOW);
 DateVar BOW:= BOM - DayOfWeek(BOM) + DOW  + (7*(Week-1))