Please enable JavaScript to view this site.

 

str = StrDatesConcatenateEx(sDateString, sDateSeparator, sConcatChar, sTwoDaySeparator, bSortInput)

 

This macro function takes a string containing a series of day numbers and returns a string in which ascending runs of consecutive numbers are shortened. It extends StrDatesConcatenate with support for leading zeros, a separate separator for two-day runs, optional numeric sorting, and runs of more than 16 consecutive days.

 

For example, with a slash between two consecutive days and a hyphen for longer runs, 01,02,04,05,06 becomes 01/02,04-06.

 

Parameters

 

sDateString — The input list of positive integer day numbers. Each number may be followed immediately by one asterisk (*). Spaces around each entry are ignored. An empty or whitespace-only string returns an empty string.

 

sDateSeparator — The separator between input entries. The same separator is used between separate output runs. It must not be empty. The complete separator is matched, including any spaces, and may contain more than one character.

sConcatChar — The text placed between the first and last numbers of a run of three or more consecutive days. It may contain more than one character.

 

sTwoDaySeparator — The text placed between the two numbers of a run containing exactly two consecutive days. Use sDateSeparator to leave these as separate dates, or sConcatChar to display them like longer ranges.

 

bSortInput — Use true to sort the input numerically in ascending order before identifying runs. Use false to preserve the input order. Sorting retains the original relative order of entries with equal numeric values.

 

Leading zeros and consecutive runs

 

Numbers are compared by their numeric values. Leading zeros are preserved on displayed numbers; the function does not add zeros or impose a common width. Thus 01,02,03 becomes 01-03, while 1,02,003 becomes 1-003 when sConcatChar is a hyphen.

 

A run consists of adjacent entries whose numeric values increase by one and whose asterisk status is the same. Each complete run is formatted once. There is no fixed run-length limit: all days from 01 through 31 can be returned as 01-31.

 

Duplicate numbers are retained and interrupt a run. For example, 1,1,2,3 becomes 1,1-3 with a hyphen as sConcatChar. Without sorting, descending numbers are not combined.

 

Days followed by an asterisk

 

Only days with the same asterisk status are combined. In a run of three or more starred days, the asterisk appears after the final number: 01*,02*,03* becomes 01-03*. In a two-day run, both displayed numbers retain their asterisks: 01*,02* becomes 01*/02* when sTwoDaySeparator is a slash. A change between starred and unstarred entries interrupts a run.

 

Examples

sResult = StrDatesConcatenateEx('01,02,04,05,06', ',', '-', '/', false)
// sResult = '01/02,04-06'

sResult = StrDatesConcatenateEx('03,01,02,10', ',', '-', '/', true)
// sResult = '01-03,10'

sResult = StrDatesConcatenateEx('03,01,02,10', ',', '-', '/', false)
// sResult = '03,01/02,10'

sResult = StrDatesConcatenateEx('01,02', ',', '-', ',', false)
// sResult = '01,02'

sResult = StrDatesConcatenateEx('03; 01; 02', '; ', ' to ', ' & ', true)
// sResult = '01 to 03'

sResult = StrDatesConcatenateEx('01*,02*,03*,05*,06*,07', ',', '-', '/', false)
// sResult = '01-03*,05*/06*,07'

sResult = StrDatesConcatenateEx('01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20', ',', '-', '/', false)
// sResult = '01-20'

 

Input requirements

 

Use a list of individual positive decimal integers, optionally followed immediately by one asterisk. Existing ranges such as 1-3, empty entries within a nonempty list, zero, negative numbers, other characters, and values above 2147483647 are invalid. Leading, trailing, or repeated separators create empty entries and are invalid. Choose an input separator that cannot be confused with digits or the asterisk suffix.

 

Values above 31 are accepted, allowing lists of day-of-year numbers. The function compares numbers only; it does not interpret months, years, or calendar boundaries. For example, 30,31,1,2 is not a single consecutive run across a month boundary.

 

The result is formatted text and may contain ranges or different separators. It should not be passed back to this function as an input list.

 

See also: StrDatesConcatenate.

 


Topic 189965, last updated on 09-Oct-2026