Splunk Search

Comparing the Dates and retrieve the latest value

RonD
Explorer

We have a search that populates a csv file for tracking purposes of latest check-ins formatted as (%m/%d/%Y)

Hostagent1_dateagent2_dateagent3_dateagent4_dateagent5_date
Asset111/16/202011/15/202011/16/202011/13/202011/16/2020
Asset211/15/2020 11/13/202011/13/202011/13/2020

How do I go about on comparing all these dates and get the latest value and write it to a new column - latest date

Expected outcome:

Hostagent1_dateagent2_dateagent3_dateagent4_dateagent5_datelatest_date
Asset111/16/202011/15/202011/16/202011/13/202011/16/202011/16/2020
Asset211/15/2020 11/13/202011/13/202011/13/202011/15/2020

 

Labels (5)
0 Karma
1 Solution

rnowitzki
Builder

Hi  @RonD ,


Maybe not the most dynamic solution, but it should work:

|  eval latest_date=strftime(max(strptime(agent1_date,"%m/%d/%Y"),strptime(agent2_date,"%m/%d/%Y"),strptime(agent3_date,"%m/%d/%Y"),strptime(agent4_date,"%m/%d/%Y"),strptime(agent5_date,"%m/%d/%Y")),"%m/%d/%Y")


The strptime and strftime is to convert it to epoch and back to "humand readable" in order to make the dates comparable.

Hope it helps
BR
Ralph 

--
Karma and/or Solution tagging appreciated.

View solution in original post

RonD
Explorer

Thank you, this is actually working well for my requirements!

0 Karma

rnowitzki
Builder

Hi  @RonD ,


Maybe not the most dynamic solution, but it should work:

|  eval latest_date=strftime(max(strptime(agent1_date,"%m/%d/%Y"),strptime(agent2_date,"%m/%d/%Y"),strptime(agent3_date,"%m/%d/%Y"),strptime(agent4_date,"%m/%d/%Y"),strptime(agent5_date,"%m/%d/%Y")),"%m/%d/%Y")


The strptime and strftime is to convert it to epoch and back to "humand readable" in order to make the dates comparable.

Hope it helps
BR
Ralph 

--
Karma and/or Solution tagging appreciated.
Get Updates on the Splunk Community!

Stay Connected: Your Guide to January Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...

[Puzzles] Solve, Learn, Repeat: Reprocessing XML into Fixed-Length Events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...