Crystal Reports Training by Ken Hamady, MS, Reporting and Training Nationwide On Location TrainingPublic ClassesIndividual TrainingIntroductory Course OutlineAdvanced Course OutlineFormula ExamplesNewsletter Back IssuesMy BlogResource LibraryConsulting ServicesSupport ServicesContact InformationLinks to third party productsBack to main pageMy Credentials
Free Crystal Reports formula examples from KenHamady.com


To learn the techniques used in these formulas get:


The Expert's Guide to Crystal Reports Formulas
and
 Expert Techniques for Crystal Reports I, II & III

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))