Splunk Search

Evaluate difference between 2 (string) dates in the same event.

bjbrookz
Explorer

Hello, I'm struggling mightily with this one. I have two dates in the same event, both are strings.  Their format is below. I would like to evaluate the number of days between the firstSeen and lastSeen dates. I would also like to evaluate the number of days since firstSeen and when the search is performed. Any help would be much appreciated... 

 

firstSeen: Aug 27, 2022 20:18:37 UTC

lastSeen: Jun 23, 2024 06:17:25 UTC

Labels (3)
0 Karma
1 Solution

Tom_Lundie
Contributor

Hi,

You can do that with an eval command.

| eval firstSeenTS = strptime(firstSeen, "%b %d, %Y %H:%M:%S %Z"),
lastSeenTS = strptime(lastSeen, "%b %d, %Y %H:%M:%S %Z"),
firstLastDiff = (lastSeenTS - firstSeenTS)/86400,
firstNowDiff = (now() - firstSeenTS)/86400

If you want to round your days down to whole numbers you can use floor()

View solution in original post

Tom_Lundie
Contributor

Hi,

You can do that with an eval command.

| eval firstSeenTS = strptime(firstSeen, "%b %d, %Y %H:%M:%S %Z"),
lastSeenTS = strptime(lastSeen, "%b %d, %Y %H:%M:%S %Z"),
firstLastDiff = (lastSeenTS - firstSeenTS)/86400,
firstNowDiff = (now() - firstSeenTS)/86400

If you want to round your days down to whole numbers you can use floor()

bjbrookz
Explorer

Outstanding. That worked perfectly. Thank you. 

0 Karma
Get Updates on the Splunk Community!

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 ...

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...