Getting Data In

Between two timestamp fields, how to compare and determine which timestamp is the later time?

bretai2k
New Member

First, I'd like to apologize because I am new to Splunk development, and am trying to learn how to do things.

I have timestamp fields (formatted %Y-%m-%d %H:%M:%S) from two different sources, timeA and timeB. I've got both sources successfully joined, but now I need to compare the two fields and determine which date is the later date. I want to assign the later of the two dates to a new field. Also, sometimes either date could be blank (and in a few cases, they're both blank).

Does anyone know how to do this? I've had a hard time figuring anything out in the docs.

TIA,
Ryan

0 Karma
1 Solution

niketn
Legend

You need to determine whether timestamp is in epoch format or string format. If they are string time you need to convert to epoch first. Try the following:

 <Your Base Search>
| eval Time1=if(isnull(Time1),0,Time1)
| eval Time2=if(isnull(Time2),0,Time2)
| eval Time3=if(Time1>Time2,Time1,Time2)

For understanding time fields and conversions you can check out

https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions#Date_and_Tim...
https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert
http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

DalJeanis
Legend

In the given format, they can be compared directly. Year, month, day, hour, minute, second are already in descending order of significance. The only caveat is whether they are in the same time zone, but you don't have a time zone qualifier (%Z) on the format, so you can just say

if(timeA < timeB,timeB,timeA)

0 Karma

niketn
Legend

You need to determine whether timestamp is in epoch format or string format. If they are string time you need to convert to epoch first. Try the following:

 <Your Base Search>
| eval Time1=if(isnull(Time1),0,Time1)
| eval Time2=if(isnull(Time2),0,Time2)
| eval Time3=if(Time1>Time2,Time1,Time2)

For understanding time fields and conversions you can check out

https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions#Date_and_Tim...
https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Convert
http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

bretai2k
New Member

Worked perfectly! Thank you niketnilay

0 Karma
Get Updates on the Splunk Community!

AI for AppInspect

We’re excited to announce two new updates to AppInspect designed to save you time and make the app approval ...

App Platform's 2025 Year in Review: A Year of Innovation, Growth, and Community

As we step into 2026, it’s the perfect moment to reflect on what an extraordinary year 2025 was for the Splunk ...

Operationalizing Entity Risk Score with Enterprise Security 8.3+

Overview Enterprise Security 8.3 introduces a powerful new feature called “Entity Risk Scoring” (ERS) for ...