Symptom
How to find week Number of a month using date in Crystal Reports
Environment
Crystal Reports 2008(All Versions)
Resolution
1. Open Crystal Reports and Create a formula using the below code,
datevar endDate := currentdate; //replace currentdate with whatever date you want to find
datevar startDate := date(year(currentdate),month(currentdate),01); //find the first day of month
datediff("ww" ,startDate,endDate,crsunday) + 1
2. Place it on detail section.
OR
1. Create a formula in formula editor using the following code
dateVar myDate := cdate(#01/31/2010#); //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";
" Week " + WeekNum
Keywords
Week number in a month, week formula, week in a month , KBA , BI-RA-CR-DSL , Crystal Reports on Data Semantic Layer , How To
SAP Knowledge Base Article - Public