Quantcast
Channel: Calculate date from week number - Stack Overflow
Browsing all 27 articles
Browse latest View live

Answer by Fourier for Calculate date from week number

As suggested by khellang (sorry but I cannot add comments), with .NET Core is quite simple. This is my piece of code:var today = DateTime.Today;CultureInfo myCI = new CultureInfo("it-IT");Calendar...

View Article



Answer by br3nt for Calculate date from week number

One of the biggest problems I found was to convert from weeks to dates, and then from dates to weeks.The main problem is when trying to get the correct week year from a date that belongs to a week of...

View Article

Answer by khellang for Calculate date from week number

UPDATE: .NET Core 3.0 and .NET Standard 2.1 has shipped with this type.Good news! A pull request adding System.Globalization.ISOWeek to .NET Core was just merged and is currently slated for the 3.0...

View Article

Answer by Vitalij Roscinski for Calculate date from week number

Lightly changed Mikael Svenson code. I found the week of the first monday and appropriate change the week number. DateTime GetFirstWeekDay(int year, int weekNum) { Calendar calendar =...

View Article

Answer by realbart for Calculate date from week number

Currently, there is no C# class that correctly handles ISO 8601week numbers. Even though you can instantiate a culture, look for the closest thing and correct that, I think it is better to do the...

View Article


Answer by Learner for Calculate date from week number

I have written and tested the following code and is working perfectly fine for me. Please let me know if anyone face trouble with this, I have posted a question as well in order to get the best...

View Article

Answer by Oskar Sjöberg for Calculate date from week number

I simplified the code Mikael Svensson provided which is correct for many countries in Europe.public static DateTime FirstDateOfWeekIso8601(int year, int week){ var firstThursdayOfYear = new...

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


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 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 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 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 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 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 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 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 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 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 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 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
Browsing all 27 articles
Browse latest View live




Latest Images