Expand my Community achievements bar.

SOLVED

Pulling the Max Date From An Array Of Differently Formatted Date Fields

Avatar

Level 4

Hello,

 

I am trying to pull the latest/max date from an array of differently formatted dates:
Here is the data I am pulling into an array. The different highlights show that some dates have a timestamp while others do not.

Eric_D_Miller_0-1746194725327.png

Here is a good example of a bunlde in my array:

Eric_D_Miller_1-1746195258810.png

The goal is to get the latest date from each bundle, and apply that date to new field. 

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 6

Maybe someone else has a more elegant solution but this is what I came up with. Dates with no time automatically default to 12:00am

 

Lawson02_0-1746472474863.png

Lawson02_2-1746472506855.png

 

Lawson02_3-1746472517455.png

Lawson02_4-1746472533019.png

 

View solution in original post

4 Replies

Avatar

Correct answer by
Level 6

Maybe someone else has a more elegant solution but this is what I came up with. Dates with no time automatically default to 12:00am

 

Lawson02_0-1746472474863.png

Lawson02_2-1746472506855.png

 

Lawson02_3-1746472517455.png

Lawson02_4-1746472533019.png

 

Avatar

Community Advisor

Data from my arrayData from my array

data from the array

 

reverse sort descending, group by hourIDreverse sort descending, group by hourID

reverse sort descending by hour entryDate

 

reverse sorted datareverse sorted datagrab only the first array item for each hourID (bundle)grab only the first array item for each hourID (bundle)

get 1st entry from the sorted array

 

lates entry from each bundlelates entry from each bundle

Avatar

Level 4

Thank you Randy,

 

Each of my bundles have 11 different date fields that may or may not be populated. My goal is to end up with only one date value from each bundle which should be the latest date.

 

Your example is helpful but in it there is only one date, entryDate. How can I apply what you instructed but considering my bundles have eleven date fields instead of just one?

Avatar

Community Advisor

I think @Lawson02's answer is elegant and simple. By converting the date value to a timestamp, there is no need to sort/reverse since we're now in math-land and can use max/min etc. Added bonus, if you go from a true date field (ie not a text field) you avoid timezone headaches by converting to a timestamp.

 

Only change I would make is to set vars separately, so if needed to can cleanup the value before parsing - but still same approach as Lawson provided.

SveniX_0-1746807101944.png