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!

A Four-Part Event Series: Full Stack Observability For the AI Era

As AI reshapes applications, infrastructure, and the way teams operate, the traditional boundaries of ...

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...