How to get first and last date given a year and a weeknr
-
Hello and thanks for your reply. I don´t see how it would be that easy though. Could you give a pointer of how you would solve my problem with datetime-class? I´ve been trying to use System.Globalization.Calendar with AddWeeks etc, but have yet to make it work.
livez wrote:
Could you give a pointer of how you would solve my problem with datetime-class?
Create a DateTime object with the relevant date, add or subtract one day until it's the first day of the week (i.e Sunday or Monday), save that date. Add one day until it's the last day of the week, save that date. Look at the DateTime members to see what is possible.
-
Hello! Im trying to figure out how I get the dates for the first and last day of a given year and week. For instance: year: 2009 week:53 = 2009/12/28 - 2010/01/03 year: 2010 week:1 = 2010/01/04 - 2010/01/10 Does anyone know how to achieve this?
This might help: http://en.wikipedia.org/wiki/ISO_week_date[^] It tells you how to calculate the week number for any given date, so it shouldn't be too hard to "reverse engineer" it to come up with the date corresponding to a given week number.
-
This might help: http://en.wikipedia.org/wiki/ISO_week_date[^] It tells you how to calculate the week number for any given date, so it shouldn't be too hard to "reverse engineer" it to come up with the date corresponding to a given week number.
-
Richard MacCutchan wrote:
I already got my code to work.
Teacher's pet! ;P
-
livez wrote:
Could you give a pointer of how you would solve my problem with datetime-class?
Create a DateTime object with the relevant date, add or subtract one day until it's the first day of the week (i.e Sunday or Monday), save that date. Add one day until it's the last day of the week, save that date. Look at the DateTime members to see what is possible.
-
"Create a DateTime object with the relevant date" But its the relevant date I dont have. I have a year and a weeknr. How do I create a relevant datetime-object with that?
-
Richard MacCutchan wrote:
I already got my code to work.
Teacher's pet! ;P
-
Create a DateTime(year, 1, 1) Adjust by day until the day is Thursday to get it to week 1 Add 7 x week number Adjust day back and forward to find Monday and Sunday
-
Create a DateTime(year, 1, 1) Adjust by day until the day is Thursday to get it to week 1 Add 7 x week number Adjust day back and forward to find Monday and Sunday