Quantcast
Channel: Calculate date from week number - Stack Overflow
Browsing index pages (27 articles)

Calculate date from week number

Anyone know an easy way to get the date of the first day in the week (monday here in Europe). I know the year and the week number? I'm going to do this in C#.

View Article


Answer by Jon Skeet for Calculate date from week number

The easiest way is probably to find the first Monday of the year, and then add the relevant number of weeks. Here's some sample code. It assumes a week number starting at 1, by the way:using...

View Article


Answer by amaca for Calculate date from week number

Week 1 is defined as being the week that starts on a Monday and contains the first Thursday of the year.

View Article

Answer by ℍℍ for Calculate date from week number

NoteThe below answer uses the .NET Calendar rules. It does not promise ISO8601 conformance. See some of the other answers here when you need that. Week numbering is a mess, always try to find out what...

View Article

Answer by Alexander Kahoun for Calculate date from week number

Personally I'd take advantage of the culture info to get the day of the week and loop down to the culture's first day of the week. I'm not sure if I'm explaining it properly, here's an example: public...

View Article


Answer by idstam for Calculate date from week number

According to ISO 8601:1988 that is used in Sweden the first week of the year is the first week that has at least four days within the new year.So if your week starts on a Monday the first Thursday any...

View Article

Answer by Thomas for Calculate date from week number

I like the solution provided by Henk Holterman. But to be a little more culture independent, you have to get the first day of the week for the current culture ( it's not always monday ):using...

View Article

Answer by Simon for Calculate date from week number

using Fluent DateTime http://fluentdatetime.codeplex.com/ var year = 2009; var firstDayOfYear = new DateTime(year, 1, 1); var firstMonday = firstDayOfYear.Next(DayOfWeek.Monday); var weeksDateTime =...

View Article


Answer by Robert L for Calculate date from week number

To convert in both directions, see here: Wikipedia article on ISO week dates

View Article


Answer by QuinnG for Calculate date from week number

Assuming the week number starts at 1DateTime dt = new DateTime(YearNumber, 1, 1).AddDays((WeekNumber - 1) * 7 - (WeekNumber == 1 ? 0 : 1));return dt.AddDays(-(int)dt.DayOfWeek);This should give you the...

View Article

Answer by pasx for Calculate date from week number

I improved a little on Thomas' solution with an override: public static DateTime FirstDateOfWeek(int year, int weekOfYear) { return Timer.FirstDateOfWeekOfMonth(year, 1, weekOfYear); } public static...

View Article

Answer by user687474 for Calculate date from week number

The free Time Period Library for .NET includes the ISO 8601 conform class Week:// ----------------------------------------------------------------------public static DateTime GetFirstDayOfWeek( int...

View Article

Answer by GEORGE BAXTER for Calculate date from week number

I tried some codes above and some have small mistakes, when you try different years with different starting days of week you will see them, I took the code of Jon Skeet, fix it and it works, very...

View Article


Answer by Mikael Svenson for Calculate date from week number

I had issues with the solution by @HenkHolterman even with the fix by @RobinAndersson.Reading up on the ISO 8601 standard resolves the issue nicely. Use the first Thursday as the target and not Monday....

View Article

Answer by user1564287 for Calculate date from week number

I used one of the solutions but it gave me wrong results, simply because it counts Sunday as a first day of the week.I changed: var firstDay = new DateTime(DateTime.Now.Year, 1, 1).AddDays((weekNumber...

View Article


Answer by Axiom255 for Calculate date from week number

The proposed solution is not complete - it only works for CalendarWeekRule.FirstFullWeek. Other types of week rules do not work. This can be seen using this test case:foreach (CalendarWeekRule rule in...

View Article

Answer by Axiom255 for Calculate date from week number

I have made a refined version of the proposed solution that is a simpler and parametrises the firstDayOfWeek:public static DateTime GetFirstDayOfWeek(int year, int week, DayOfWeek firstDayOfWeek){...

View Article


Answer by Paolo Marani for Calculate date from week number

This one worked for me, it also have the advantage of expecting a cultureinfo as parameter to test the formula with different cultures. If empty, it gets the current culture info... valid values are...

View Article

Answer by Samer Adra for Calculate date from week number

Here is a method that is compatible with the week numbers that Google Analytics, and also the same numbering scheme we used internally at Intel, and which I'm sure is also used in a lot of other...

View Article

Answer by José Ignacio Becerra Becerra for Calculate date from week number

this is my solution when we want to calculate a date given year, week number and day of the week.int Year = 2014;int Week = 48;int DayOfWeek = 4;DateTime FecIni = new DateTime(Year, 1, 1);FecIni =...

View Article
Browsing index pages (27 articles)


Latest Images