>CLEAR > >LOCAL Test AS Date >LOCAL Stop AS Integer >LOCAL WeekIndex AS Integer > >m.Test = {^2017-01-01} >m.Stop = YEAR(m.Test) + 1 >DO WHILE YEAR(m.Test) != m.Stop > * go through 5 weeks, even if the month only has 4 (in this case, the 5th will hold the same value of the first of the following month) > FOR m.WeekIndex = 1 TO 5 > ? TEXTMERGE("<<YEAR(m.Test)>>/<<MONTH(m.Test)>>, <<m.WeekIndex>> = <<MonthWeekToYearWeek(m.Test, m.WeekIndex)>>") > ENDFOR > m.Test = GOMONTH(m.Test, 1) >ENDDO > >#DEFINE DEFAULT_FIRSTWEEK 3 >#DEFINE DEFAULT_FIRSTDAYOFWEEK 2 > >FUNCTION MonthWeekToYearWeek (ReferenceDate AS Date, MonthWeek AS Integer, FirstWeek AS Integer, FirstDayOfWeek AS Integer) AS Integer > > LOCAL FirstDayOfReferenceWeek AS Date > > * set your defaults > IF PCOUNT() < 3 > m.FirstWeek = DEFAULT_FIRSTWEEK > ENDIF > IF PCOUNT() < 4 > m.FirstDayOfWeek = DEFAULT_FIRSTDAYOFWEEK > ENDIF > > * calculate the first day of the reference week in the reference month > > * start at the beginning of the year > m.FirstDayOfReferenceWeek = DATE(YEAR(m.ReferenceDate), 1, 1) > > * get the first day of the year that it is in the first week of the year > * for a single week mode - the default, for instance - this could be make simpler, > * but this method adjusts to the different settings defined by the WEEK() parameters > DO WHILE WEEK(m.FirstDayOfReferenceWeek, m.FirstWeek, m.FirstDayOfWeek) != 1 > m.FirstDayOfReferenceWeek = m.FirstDayOfReferenceWeek + 1 > ENDDO > > * now jump closer to the equivalent day in the reference month (in steps of 7 * 4 days - the minimum month length) > m.FirstDayOfReferenceWeek = m.FirstDayOfReferenceWeek + (MONTH(m.ReferenceDate) - 1) * 28 > * eventually, we'll have to step further, once or twice > DO WHILE MONTH(m.FirstDayOfReferenceWeek) < MONTH(m.ReferenceDate) > m.FirstDayOfReferenceWeek = m.FirstDayOfReferenceWeek + 7 > ENDDO > > * we have by now the first day of the first week of the month, we can step to the the required week in the month > m.FirstDayOfReferenceWeek = m.FirstDayOfReferenceWeek + (m.MonthWeek - 1) * 7 > > * return the corresponding year week > RETURN WEEK(m.FirstDayOfReferenceWeek, m.FirstWeek, m.FirstDayOfWeek) > >ENDFUNC >Antonio,