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 Last Friday of a Month (or any other day of the week):

The following formula will allow you to find the last Friday of any month, based on an 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 the field Order Date.   You can also change the formula to find another day of the week by changing the number 6 to any number from 1 to 7.  Use 1 for Sunday and 7 for Saturday, etc.

WhileReadingRecords;
Local DateVar DIn:= {Orders.Order Date};   //Your date field/parameter or CurrentDate
Local NumberVar DOW:= 6;    // Your target DayOfWeek - any number from 1 to 7, with 1 for Sunday

DateVar  DDow :=
    if day(DIn) < 20
    then DIn - DayOfWeek(DIn) + DOW
    else DIn - DayOfWeek(DIn) - 7 + DOW;

if Month (DDow+35) = Month(DDow) then (DDow+35) else
if Month (DDow+28) = Month(DDow) then (DDow+28) else
if Month (DDow+21) = Month(DDow) then (DDow+21) else
if Month (DDow+14) = Month(DDow) then (DDow+14) else
if Month (DDow+ 7) = Month(DDow) then (DDow+ 7) else DDow