Version

GetWeekNumberForDate(SmartDate,Int32) Method

Returns the week number for a particular date using the current WeekRule and FirstDayOfWeekResolved.
Syntax
'Declaration
 
Public Overloads Function GetWeekNumberForDate( _
   ByVal date As SmartDate, _
   ByRef yearContainingWeek As Integer _
) As Integer
public int GetWeekNumberForDate( 
   SmartDate date,
   out int yearContainingWeek
)

Parameters

date
SmartDate
yearContainingWeek
Out integer to receive the year for which the week number belongs.

Return Value

Integer denoting the week number that the date belongs to.
Remarks

The System.Globalization.Calendar's GetWeekOfYear method simply returns the number of weeks into the year that the date falls on. It does not seem to use the weekrule specified in the arguments. e.g. If the first day of week is sunday and the weekrule is Jan 1, then 12/31/2000 (Sunday) should return 1. Instead it returns 54 and 1/1/2001 (Monday) returns 1.

This routine returns the correct week number for the specified date based on the WeekRule and FirstDayOfWeekResolved.

Note, this may be a week for a year other than the year of the date. e.g. 12/31/2000, week rule of Jan 1, and week start of sunday will return 1 because this date falls into the first week of the year 2001.

Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also