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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...