datecrystal-reportscrystal-reports-xi

LastFullWeek starting with monday in crystal reports


When using LastFullWeek i get the last Sunday - Saturday week, but for my reports i want the last Monday - Sunday week. Is there any simple way to get this behaviour, or do I have to write my own function for it (which isn't that hard, but unconvenient for such a common date span.)


Solution

  • custom function:

    //LastFullWeekEx
    Function (DateVar date, Optional NumberVar firstDayOfWeek := crSunday)
      (date - DayOfWeek(date, firstDayOfWeek)) - 6 TO (date - DayOfWeek(date, firstDayOfWeek))
    

    usage:

    // use with non-volatile DataDate and Sunday
    {TABLE.DATE} IN LastFullWeekEx(DataDate)
    
    // use with non-volatile DataDate and Monday
    {TABLE.DATE} IN LastFullWeekEx(DataDate, crMonday)
    

    testing:

    // should return True
    ( Minimum(LastFullWeek) = Minimum(LastFullWeekEx(DataDate, crSunday)) ) AND
    ( Maximum(LastFullWeek) = Maximum(LastFullWeekEx(DataDate, crSunday)) )