You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Converting Week Number to Date (Apple Numbers)

YearWeek Number Start Date (Monday) End Date (Sunday)
20124
20135
20186
201833
201138


Who has a formula that works in Apple Numbers to give me the start date of any given week and the end date of any given week for any year and week number I choose? So looking at the table above.... what was the start date for week 4 in 2012, for example. Assume the table has column numbers and row numbers like a spreadsheet so the question would refer to A2 (year) and B2 (weeknum) Tried various excel formulas but can't make this work in Numbers. Please can you help?

Mac Pro, macOS Mojave (10.14.1), Numbers version 5.3 (5989)

Posted on Dec 3, 2018 1:19 PM

Reply
Question marked as Top-ranking reply

Posted on Dec 4, 2018 2:10 AM

I get confused by the ISO weeks but I think it is correct to say that the Thursday of ISO week 1 will always be first Thursday of the calendar year. If so, I think this works:


User uploaded file


The formula in C2, filled down:


=(DATE(A2,1,1)+B2*7)−WEEKDAY(DATE(A2,1,3))−3


The formula in D2, filled down:


=C2+6


That -3 at the end "counts back" from Thursday to a Monday.


Substitute ; for , in the formula if your region uses , as a decimal separator.



SG

8 replies
Question marked as Top-ranking reply

Dec 4, 2018 2:10 AM in response to cyberwolfsec

I get confused by the ISO weeks but I think it is correct to say that the Thursday of ISO week 1 will always be first Thursday of the calendar year. If so, I think this works:


User uploaded file


The formula in C2, filled down:


=(DATE(A2,1,1)+B2*7)−WEEKDAY(DATE(A2,1,3))−3


The formula in D2, filled down:


=C2+6


That -3 at the end "counts back" from Thursday to a Monday.


Substitute ; for , in the formula if your region uses , as a decimal separator.



SG

Dec 3, 2018 3:49 PM in response to cyberwolfsec

Here's a start. It's limitations are that it is restricted to a single year due to that restriction in the lookup table.

Currently working on an expanded version to fit your specification more closely.

User uploaded file

Thr table on the right calculates the week number for the first eight days of the year specified in A1.

In the larger table, the formula in column C gets the week wanted for column A, looks up the start of week 2 in the lookup table, then adds 7*one less than the number in column B to that date to get the end date of the desired week.

The formula in column B subtracts 6 from the result (in column C) to get the start date of the same week.


Exceptions: Week 1 always starts on January 1. The last week of the year (52 or 53) always ends on Dec 31. I've not handled either of those in the formulas as yet.


I've not included the formulas used in the tables as some revisions came to mnd as this was being written.


More to come.


Regards,

Barry

Dec 3, 2018 5:40 PM in response to cyberwolfsec

More:


This version allows entering a specific year and week number and getting the start and end dates of that week.

It has covered the first week issue mentioned above, but not the 'last week' issue.

The larger lookup table (on the right) calculates the weeknum for the first eight days of the year entered in column A, and the day number of the last day of week 1 in column B.


User uploaded file

First Week:


Columns A and B are Header columns.


Column A: Entered data.

Enter the year numbers of the years for which you want to be able to calculate the start and end dates. The years do not need to be consecutive or sorted.


Column B: Calculated data.


B2: MATCH(1,C2:J2,1)

Filled down the rest of column B.

MATCH searches for the value 1 in the range C2 to J2 and returns the position in the list of the 'first' occurrence of the search value found. The third argument (1) tells match to accept the 'largest value less than or equal to' the search value. Its use here is to force MATCH to start its search at the 'bottom' (right end) of the list and move toward the top (left side) ensuring the the first acceptable value is the 1 furthest right in the list, corresponding to the last day of week 1.


C2: WEEKNUM(DATE($A2,1,1+COLUMN()−3),2)

Filled right to J2, then all filled down to the bottom of the table.


DATE($A2,1,1+COLUMN()−3),

DATE uses the year in this row of column A, the month number (1) and the day number (1 plus three less than the number of 'this column') to construct the dates of the first eight days of the year. The result is passed to WEEKNUM, which returns the weeknumber for that date.


Main


Columns A and B of Main contain entered data; the number of the year in each row of column A, and the desired week number in column B.


D2: IF(OR(LEN(A2)<1,LEN(B2)<1),"",DATE(A2,1,VLOOKUP(A2,First week::A:B,2,FALSE))+7×(B2−1))


The core part of the formula, shown in bold, gets the year value in column A, searches for it in the first column (A) of the lookup table (columns A and B of First week), and on finding it, returns the value in the second column of that table. FALSE refers to acceptance of a 'close match' (same definition as MATCH's "find largest"). Set to FALSE, VLOOKUP will accept only an exact match for the year, and will return an error message if that cannot be found.


The returned value, the day number of the last day of week 1, is handed to DATE which uses the year value from A2, the month number (1) and the day number returned by VLOOKUP to construct the date of the last day of week 1 of that year.

The last part, +7*(B2-1) multiplies one less than the desired week by the number of days in a week, then adds the result to the date returned by VLOOKUP to get the end date of the desired week.


C2: IF(OR(LEN(A2)<1,LEN(B2)<1),"",MAX(DATE(A2,1,1),D2−6))


The core part of this formula, shown in bold, returns the greater of January 1 of the year specified or the date six days before the value in D2. see also note below)


Both formulas also contain a 'switch' (shown in normal type) which checks for content in this row of columns A and B by 'measuring' the length of the entry on each of the cells in number of characters. If either cell contains less than one character, IF returns a null string, leaving th cell appearing 'blank', and exits.


Note: The end of December issue:


Just as MAX provides a low limit (Jan 1) on the start date of Week 1, MIN can do the opposite for the last day of week 53. Make this small edit to the formula in D2 (and filled down):


original: D2:

IF(OR(LEN(A2)<1,LEN(B2)<1),"", DATE(A2,1,VLOOKUP(A2,First week::A:B,2,FALSE))+7×(B2−1))

revised:D2:

IF(OR(LEN(A2)<1,LEN(B2)<1),"",MIN(DATE(A2,12,31),DATE(A2,1,VLOOKUP(A2,First week::A:B,2,FALSE))+7×(B2−1)))


Spaces inserted in original to align identical parts. Revisions shown in bold.


Regards,

Barry

Dec 4, 2018 6:56 AM in response to cyberwolfsec

cyberwolfsec wrote:


SGIII - thanks - I think that is right under ISO-8601 but this is part of what is bugging me.... if you do the formula backwards on the date calculated for week 1:

WEEKNUM(C2,2) it returns 53.... why is that. Shouldn't they agree?

Year

ISO-8601 Weeknum

Start Date

End Date

WeekNum() Formula for Start Date

WeekNum() Formula for End Date

2015

1

29/12/2014

04/01/2015

53

1

2016

1

04/01/2016

10/01/2016

2

2

2017

1

02/01/2017

08/01/2017

2

2

2018

1

01/01/2018

07/01/2018

1

1

































As you've seen Numbers doesn't have a an ISOWEEKUM function the way Excel now has. So, just and in the old days of Excel, you have to use an ugly formula something like this:


User uploaded file


=INT((DUR2DAYS(C2−DATE(YEAR(C2−WEEKDAY(C2−1)+4),1,3))+WEEKDAY(DATE(YEAR(C2−WEEKD AY(C2−1)+4),1,3))+5)/7)


I confess I don't understand exactly how all this works. 🙂 I adapted it from a formula I saw from a Google search.


SG

Dec 3, 2018 4:05 PM in response to Barry

Yes... but using an array/lookup table is super limited. Imagine you need the answer for any random year and any random week. A lookup table would break after a few rounds.


Also, ISO week-numbering year needs to be observed - https://en.wikipedia.org/wiki/ISO_week_date


I am trying not to do this in Excel but it would pretty easy to do in VB. I am hoping to ditch Microsoft Office 365 for numbers. But it is all too tempting to want to write code. However, surely it is possible in apple number functions?


What is needed is to calculate when week 1 is and then work from there forwards. The week starts always on a Monday and then it ends on a Sunday. So that makes the start date and end date reasonably easy once you know how many weeks to move forward from week 1.


Definition of Week 1:


The ISO 8601 definition for week 01 is the week with the Gregorian year's first Thursday in it. The following definitions based on properties of this week are mutually equivalent, since the ISO week starts with Monday:

  • It is the first week with a majority (4 or more) of its days in January.
  • Its first day is the Monday nearest to 1 January.
  • It has 4 January in it. Hence the earliest possible first week extends from Monday 29 December (previous Gregorian year) to Sunday 4 January, the latest possible first week extends from Monday 4 January to Sunday 10 January.
  • It has the year's first working day in it, if Saturdays, Sundays and 1 January are not working days.


If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, it is part of week 53 of the previous year. If it is on a Saturday, it is part of the last week of the previous year which is numbered 52 in a common year and 53 in a leap year. If it is on a Sunday, it is part of week 52 of the previous year.


So what is the formula to find Week 1 in any given year in Apple Numbers?

Dec 4, 2018 2:14 AM in response to SGIII

SGIII - thanks - I think that is right under ISO-8601 but this is part of what is bugging me.... if you do the formula backwards on the date calculated for week 1:

WEEKNUM(C2,2) it returns 53.... why is that. Shouldn't they agree?

Year

ISO-8601 Weeknum

Start Date

End Date

WeekNum() Formula for Start Date

WeekNum() Formula for End Date

2015

1

29/12/2014

04/01/2015

53

1

2016

1

04/01/2016

10/01/2016

2

2

2017

1

02/01/2017

08/01/2017

2

2

2018

1

01/01/2018

07/01/2018

1

1































Converting Week Number to Date (Apple Numbers)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.