Skip to main content

sortDateTimesReverse

This function sorts datetime objects in reverse-chronological order. The return value is a sorted list.

To sort in chronological order, use sortDateTimes instead.

All objects in the input data must have the same datetime components. Mixing objects with different components (e.g. mixing date-only objects and time-only objects) produces an error.

Parameters

Examples

The examples below use strings in an automatically recognized datetime pattern.

ATL in Script

Printed Result

[[

myDates = ('1982-02-26','1986-02-13','1955-11-16')

sortDateTimesReverse(myDates)

]]

Feb 13, 1986, Feb 26, 1982 and Nov 16, 1955

[[

myTimes = ('21:30:00','17:45:00','05:15:00')

sortDateTimesReverse(myTimes)

]]

9:30:00 PM, 5:45:00 PM and 5:15:00 AM

[[

dateTime1 = '2002-12-28T06:30:15'
dateTime2 = '2002-02-26T00:00:35'
dateTime3 = '2002-12-28T04:00:05'

myList = (dateTime1, dateTime2, dateTime3)

sortDateTimesReverse(myList)

]]

Dec 28, 2002 6:30:15 AM, Dec 28, 2002 4:00:05 AM and Feb 26, 2002 12:00:35 AM

Sorting datetime objects with timezones

To keep the ATL simple, this example uses these user-defined variables:

Name

Type

Data Source

Displayed As

date1

DATETIME

[[setTimeZone('2019-01-01T00:00:01','Europe/London')]]

Jan 1, 2019 12:00:01 AM

date2

DATETIME

[[setTimeZone('2019-01-01T00:00:02','Australia/Sydney')]]

Jan 1, 2019 12:00:02 AM

date3

DATETIME

[[setTimeZone('2019-01-01T00:00:03','Asia/Tokyo')]]

Jan 1, 2019 12:00:03 AM

Each variable returns a datetime object. Note that the setTimeZone function has assigned a timezone to each object — this timezone is not visible in the printed output because the default display pattern for datetime objects does not include timezone IDs.

However, the sortDateTimesReverse function takes the timezone into account when performing its sort.

ATL in Script

Printed Result

[[

myObjects = (date1, date2, date3)

sortDateTimesReverse(myObjects)

]]

Jan 1, 2019 12:00:01 AM, Jan 1, 2019 12:00:03 AM, and Jan 1, 2019 12:00:02 AM

The result is a list of datetime objects sorted in reverse-chronological order (latest to earliest). Bear in mind that the input objects include timezone IDs. The latest-to-earliest order for the timezones: London, Tokyo, Sydney.