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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer by Robert L for Calculate date from week number
To convert in both directions, see here: Wikipedia article on ISO week dates
View ArticleAnswer 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
More Pages to Explore .....