C# DatePart() ?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi!

I'm converting some methods of VB-class into C#-class for another project. It's quite easy, but when converting method which returns last week number of the entered year I got problems. The VB code is...

Private Function GetLastWeek(ByVal year As Integer) As Integer
'// Get last day of the year
Dim dte As DateTime = New DateTime(year, 12, 31)
'// Return last day weeknumber of the year
Return dte.Year * 100 + DatePart(DateInterval.WeekOfYear, dte, FirstDayOfWeek.Monday, FirstWeekOfYear.System)
End Function

How to do this using C# because the following code below is not working because "DatePart" is not available in C#?

private int GetLastWeek(int year)
{
// Get last day of the year
DateTime d = new DateTime(year, 12, 31);
// Return last day weeknumber of the year
return d.Year * 100 + DatePart(DateInterval.WeekOfYear, d, FirstDayOfWeek.Monday, FirstWeekOfYear.System);
}

--
Thanks in advance!

Mika
.