Re: C# DatePart() ?
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Tue, 05 Jun 2007 01:42:42 -0700
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
.
- Follow-Ups:
- Re: C# DatePart() ?
- From: Jon Skeet [C# MVP]
- Re: C# DatePart() ?
- References:
- C# DatePart() ?
- From: Mika M
- C# DatePart() ?
- Prev by Date: Thanks
- Next by Date: Re: Getting logged in user from a service?
- Previous by thread: C# DatePart() ?
- Next by thread: Re: C# DatePart() ?
- Index(es):