Splunk Search

Check if the date in splunk message is between 2 dates

ghostrider
Path Finder

I have a splunk event with below format:

{

message

{

DATE: 2023-07-20T11:53:04

}

}

I want to find all the events that have the above DATE field in a particular range. However below query is not yielding any results. Is something wrong with it?

BASE SEARCH
| message.DATE >= strftime("2023-07-20T11:50:04","%Y-%m-%dT%H:%M:%S")   AND  message.DATE <= strftime("2023-07-20T11:56:04","%Y-%m-%dT%H:%M:%S") 
Labels (4)
0 Karma

gcusello
SplunkTrust
SplunkTrust

hi @ghostrider,

your search isn't correct because there isn't a command before message.DATE.

In addition sometimes eval and where have problems with fields containing dots.

at least to compare dates, you have to transform them in epochtime using strptime, so please try this

BASE SEARCH
| rename message.DATE AS DATE
| eval DATE_epoch=strptime(DATE,"%Y-%m-%dT%H:%M:%S")
| where DATE_epoch >= strptime("2023-07-20T11:50:04","%Y-%m-%dT%H:%M:%S") AND DATE_epoch <= strptime("2023-07-20T11:56:04","%Y-%m-%dT%H:%M:%S")

 Ciao.

Giuseppe

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...