Please enable JavaScript to view this site.


int = GetNextDateForHolidayId(nHolId,nYear)


This macro function will look for the next occurrence of the holiday of ID nHolId during the year nYear.


This function is based on the current position of the holidays table's cursor and, if a next holiday is found, then the table's cursor is moved to that next holiday.


To get the first occurrence of nHolId during nYear, call the function Reset_GetNextDateForHolidayId, to move the table's cursor back to the beginning of the table, before calling the function GetNextDateForHolidayId.


Example 1: all the occurrences of a holiday in the same year


The macro code below gets the first occurrence of a holiday of nHolId during nYear, and then lists all the other ones (if there are any).

// get first occurrence, if any
nCurDate = GetNextDateForHolidayId(nHolId, nYear)
if nCurDate > 0
   sResult = 'Holiday occurs on ' + FormatDate('mmm d', nCurDate)
    // check if there is another occurrence
    nCurDate = GetNextDateForHolidayId(nHolId, nYear)
    if nCurDate > 0
      sResult = sResult + ', and on '
    while nCurDate > 0
        sResult = sResult + FormatDate('mmm d', nCurDate) + ','
        // check if there is another occurrence
      nCurDate = GetNextDateForHolidayId(nHolId, nYear)
   sResult = 'No occurrence in ' + IntToStr(nYear)

The function GetNextDateForHolidayId will find holidays that fall twice in the same year, once in early January and once in late December, as happens for Muslim holidays. But the function will also find all the occurrences of multiday holidays, as well as days in lieu.


Example 2: the occurrences of a holiday over many years


The function GetNextDateForHolidayId can also be used to find the date of a given holiday for multiple years, to generate charts of holidays such as the one below, where the order of the holidays of years 2 and 3, must follow the order of the holidays in the first year.



The macro code below implements the procedure described in the image above, first FindNextHolidayOnDate to go through the list of 2018 holidays.


Then, for each 2018 holiday, it uses GetNextDateForHolidayId to get the dates of the holiday for 2019 and 2020 (to keep the code simple, we assume that each holiday occurs once only per year).

    nStartYear nNumYears sDateFormat
    nRunDate nCurHolidayID sCurHolName nYear nCurDate
    bResult = true
    sResult = ''
    nStartYear = 2018
    nNumYears = 3
    sDateFormat = 'Dddd Mmm d'
    // run over the entire first year of the chart
    for nRunDate = EncodeDate(nStartYear,1,1to EncodeDate(nStartYear,12,31step 1
       // for each date, look for one or more holidays
        while FindNextHolidayOnDate(nRunDate,nHolSetID)
            // display the name of date of the first year
            nCurHolidayID = GetHolIdFromTable()
            sCurHolName = GetHolNameFromTable()
            sResult = sResult + sCurHolName // add the holiday name
            sResult = sResult + chr(9// a tabulation
            sResult = sResult + FormatDate(sDateFormat, nRunDate) // the date
            // then get and display the dates for years 2 to (nNumYears-1)
            for nYear = (n_TokenYear+1to (n_TokenYear+nNumYears-1step 1
                nCurDate = GetNextDateForHolidayId(nCurHolidayID,nYear)
                sResult = sResult + chr(9// a tabulation
                if nCurDate > 0
                    sResult = sResult + FormatDate(sDateFormat, nCurDate)
            sResult = sResult + chr(13// new line

See also: Reset_GetNextDateForHolidayId and FindNextHolidayOnDate.


Topic 105134, last updated on 18-Apr-2020