Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Week Number of a Month in CR 8.5? 1

Status
Not open for further replies.

antonx

Programmer
Nov 16, 2002
31
CA
Is there a Date function or or do I have to write a formula to determine the week number of a given month (see output example below)


Week Total Premium
Period Amount
Sept 2003 Week 1 $45.00 (ex. this input date would be between 09/01/2003 to 09/06/2003)
Sept 2003 Week 2 $25.00 (ex. this input date would be between 09/07/2003 to 09/13/2003)
Sept 2003 Week 3 $20.00
Sept 2003 Week 4 $30.00
Sept 2003 Week 5 $ 0.00
Oct 2003 Week 1 $10.00

 
Try this:

Insert a group on the date field. Make sure that you group it for each month. Also, Suppress the header and footer. This is needed to keep the next group in the proper order.

Create this formula:
Code:
WhileReadingRecords;
dateVar myDate := {Orders.Order Date}; //replace with your date field
numberVar DayNum := Day(myDate);
numberVar Week1Saturday := (7 - DayofWeek(Date(Year(myDate), Month(myDate), 1))) + 1;
stringVar WeekNum;

if DayNum IN [1 to Week1Saturday] then
    WeekNum := "1"
else if DayNum IN [(Week1Saturday + 1) to (Week1Saturday + 7)] then
    WeekNum := "2"
else if DayNum IN [(Week1Saturday + 8) to (Week1Saturday + 14)] then
    WeekNum := "3"
else if DayNum IN [(Week1Saturday + 15) to (Week1Saturday + 21)] then
    WeekNum := "4"
else if DayNum IN [(Week1Saturday + 22) to (Week1Saturday + 28)] then
    WeekNum := "5"
else
    WeekNum := "6";


MonthName (Month(myDate), True) + " " + ToText(Year(myDate),"0000") + " Week " + WeekNum

Group on this new formula.
Add your Summaries to Group Header 2.
Suppress the detail section.

~Brian
 
Or, another approach might be:

Datepart("ww",{table.date})+1
- Datepart("ww",{table.date} - Day({table.date})+1)

I'm not clear what your requirements are, but for the week of September 28, 2003 to October 4, 2003, if {table.date} was September 30, it would return "5", but if {table.date} was October 2, 2003, it would return "1".

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top