Click here to Skip to main content
16,016,738 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wamt to display consecutive Week number in every month for FY 2011-2012.

I want to display in below formay for FY 2011-2012.

CSS
Apr'12  May'12  Jun'12  July'12 Aug'12  Sep'12  Oct'12  Nov'12  Dec'12  Jan'13  Feb'13  Mar'13
13,14,15,16,17  18,19,20,21,22  23,24,25,26 27,28,29,30 31,32,33,34,35  36,37,38,39 40,41,42,43 44,45,46,47,48  49,50,51,52 53,1,2,3,4  5,6,7,8 9,10,11,12
Tot Weeks : 5   Tot Weeks : 5   Tot Weeks : 4   Tot Weeks : 4   Tot Weeks : 5   Tot Weeks : 4   Tot Weeks : 4   Tot Weeks : 5   Tot Weeks : 4   Tot Weeks : 5   Tot Weeks : 4   Tot Weeks : 4


How to get the week number for every month for FY 2011-2012..?
Posted

1 solution

You can use the Time Period Library for .NET[^] to count the weeks of a fiscal year.

Please note the toggles YearWeekType.Iso8601 and countOnlyFullWeek.
C#
// ----------------------------------------------------------------------
public void FiscalYearWeekCountSample()
{
  TimeCalendar calendar = new TimeCalendar( 
    new TimeCalendarConfig
    {
      YearBaseMonth = YearMonth.April,  //  April year base month
      //YearWeekType = YearWeekType.Iso8601, // ISO 8601 week numbering
      YearType = YearType.FiscalYear// treat years as fiscal years
    } );

  bool countOnlyFullWeeks = true;
  Year year = new Year( 2012, calendar );
  foreach ( Month month in year.GetMonths() )
  {
    Month nextMonth = month.GetNextMonth();
    Week week = new Week( month.Start.Date );
    int weekCount = 0;
    while ( week.Start.Date < nextMonth.Start.Date )
    {
      if ( countOnlyFullWeeks )
      {
        if ( month.HasInside( week ) )
        {
          weekCount++;
        }
      }
      else
      {
        weekCount++;
      }
      week = week.GetNextWeek();
    }
    Console.WriteLine( "Month: " + month + ", Tot Weeks : " + weekCount );
  }
} // FiscalYearWeekCountSample
 
Share this answer
 
Comments
gani7787 18-Apr-12 1:56am    
Thanks for your help.
I converted into vb.net. but, i am getting error which is highlighted in BOLD.
Error getting in key,month and year fields.

Dim calendar As New TimeCalendar(New TimeCalendarConfig() With { Key.YearBaseMonth = YearMonth.April, Key .YearType = YearType.FiscalYear })

Dim countOnlyFullWeeks As Boolean = True
Dim year As New Year(2012, Calendar)
For Each month As Month In year.GetMonths()
Dim nextMonth As Month = month.GetNextMonth()
Dim week As New Week(month.Start.[Date])
Dim weekCount As Integer = 0
While week.Start.[Date] < nextMonth.Start.[Date]
If countOnlyFullWeeks Then
If month.HasInside(week) Then
weekCount += 1
End If
Else
weekCount += 1
End If
week = week.GetNextWeek()
End While
Console.WriteLine("Month: " & month & ", Tot Weeks : " & weekCount)
Next
End Sub
Jani Giannoudis 18-Apr-12 1:59am    
Sorry, there is no bold line recognizable :). On which statement do you have the error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900