Home > Software engineering >  Print all 7 dates of a week based on month number (in a year) and week number (of exact month) in Go
Print all 7 dates of a week based on month number (in a year) and week number (of exact month) in Go

Time:02-02

I'm making a weekly template for personal planning in Google Sheets.

I have 3 variables in cells:

  • year number (2023)
  • month number (1- January, 2- February, etc)
  • week number (1 - 4 week in that month)

I need to have formula based dates printed horisontaly, that will be based on those 3 variables.

Lets say:

  • A1 - year
  • B1 - month number
  • C1 - week number (of month)

How would formula for dates look like?

UPD 1: I guess that i need to find week number inside a year firstly. And after that obtain dates of that week.

CodePudding user response:

Something like this would do it similar, but you should define how is week of the month defined. When you put 2, you expect to start from the second monday?, second sunday?, or from the 8th day?

This formula would do it from the 8th day:

=SEQUENCE(1,7,DATE(A1,B1,1 7*(C1-1)))

If you specify your logic, I can be more specific or you may be able to find it yourself!

UPDATE

Try with this to count weeks from the first monday (or previous):

=SEQUENCE(1,7,DATE(A1,B1,1)-WEEKDAY(DATE(A1,B1,1),2) 1 (C1-1)*7)
  • Related