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.
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...