Monday, February 28, 2011

Crystal Reports : Calculating the Week Number

Most reports use some kind of date math or date grouping (i.e dollars per month, week, etc).
Let us suppose we need to return the week "number" within any given year based upon a simple date. (Our fieldname will be {SALES.SALEDATE})

The DATEPART() function is what we need here:

DATEPART("ww", {SALES.SALEDATE}, crSunday)

1. The "ww" specifies that we want the "week number" returned.
2. {SALES.SALEDATE} is the date field to evaluate.
3. The final parameter, crSunday, specifies on what day the week starts.