Re: C# DatePart() ?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Tue, 05 Jun 2007 00:37:50 -0700, Mika M <mahmik_removethis@xxxxxxxxxx> wrote:

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

I think you are looking for the Calendar class. For example:

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 +
GregorianCalendar.GetWeekOfYear(d, DateTimeFormatInfo.Current.CalendarWeekRule, DayOfWeek.Monday);
}

The above explicitly uses the Gregorian calendar, but you could also use CurrentCulture.Calendar if you wanted for some reason to handle alternate calendars.

Pete
.