WOY Function for non-calendar weeks

Kenneth Brody kenbrody at spamcop.net
Tue Apr 6 07:50:34 PDT 2010


On 4/5/2010 10:52 AM, Joe Chasan wrote:
> I have a process at a site that's been working fine dividing up
> things based on WOY() function, which for most define a week as
> Sunday through Saturday.
>
> Now they want to redefine their work week as Monday through Sunday.
> WOY() takes no parameters but the subject date expression.  Does
> anyone have a routing already written that *efficiently* (key word
> there) calculates WOY using other week start/end parameters?

Well, the date functions do take an optional second parameter.  However, 
this parameter is not used, and is reserved for future enhancements, such as 
cases like this.

In the meantime, shifting the week from Sun-Sat to Mon-Sun can be done 
relatively simply.  If you subtract 1 from the date, that should do it, with 
one exception -- January 1.  This can be easily handled with using 2 lines 
instead of 1...

Week1    If:  DOY(DateToCheck) le DaysToShift
        Then:  WeekOfYear = "1"
          If:  not Week1
        Then:  WeekOfYear = WOY(DateToCheck - DaysToShift)

In this case, DaysToShift would be 1.  If, for some reason, you had a week 
defined as Tue-Mon for example, you would use 2 instead, and so on.

-- 
Kenneth Brody


More information about the Filepro-list mailing list