Calculating the week and categorizing the week based on a date

I am trying to categorize sales activities based on the date of the activity. The sales manager is wanting me to change the calculations from gathering the sales activities by month to weekly. I have a form in the database that i need to have calculate the week (maybe starting date) of the date selected. I also need the view that is used for look-ups to categorize by the week as well.

I have the following code, but it seems to not be working correctly:

D := Dates;

temp1 := @Adjust(D; 0; 0; (@Modulo(7 - @Weekday(D); 7) - 5); 0; 0; 0);

temp2 := @Text(@Month(temp1));

temp3 := @Text(@Day(temp1));

temp4 := @Right(@Text(@Year(temp1)); 2);

temp5 := @If(temp2 = “1”; “01”; temp2 = “1”; “01”; temp2 = “2”; “02”; temp2 = “3”; “03”; temp2 = “4”; “04”; temp2 = “5”; “05”; temp2 = “6”; “06”; temp2 = “7”; “07”; temp2 = “8”; “08”; temp2 = “9”; “09”; temp2);

temp6 := @If(temp3 = “1”; “01”; temp3 = “1”; “01”; temp3 = “2”; “02”; temp3 = “3”; “03”; temp3 = “4”; “04”; temp3 = “5”; “05”; temp3 = “6”; “06”; temp3 = “7”; “07”; temp3 = “8”; “08”; temp3 = “9”; “09”; temp3);

temp5 +“/” + temp6 + “/” + temp4

I would appreciate any help here.

Jamie

Subject: Calculating the week and categorizing the week based on a date

Can you give some indication as to what exactly is not “working correctly”.

One quick tip though, an easy way to pad a field with zeros is to add leading zeros then take the right 2 chars i.e.:

temp5:=@right(“0” + temp3;2);

Rufus.

Subject: RE: Calculating the week and categorizing the week based on a date

In the view, the categoizing is going by the activity date and I want to have it go by the sunday of that week. I have just found this code in another database and I will try that:@Adjust(@Now; 0; 0;

@If( (@Weekday(@Now) > 1); (8 - @Weekday(@Now)); 0);

0; 0; 0).

I am in hopes that I can get the view to have all of one week’s worth of activites categorized together so that when I complete the lookup, it finds those entires.

If you need any more info, please ask.