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!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...