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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Vibe-coding, AI, and Splunkcraft: Highlights from the .conf26 Builder Bar

If you stopped by the Builder Bar at .conf26, thank you! This year, we brought ...

Thanks for the Memories: .conf26 Took Learning to New Heights

Thank you, Splunk Community, for making .conf26 in Denver one for the books. From packed Splunk University ...

Best Practices: Splunk auto adjust pipeline queue

When you enable autoAdjustQueue in Splunk, maxSize should be understood as the queue size Splunk starts with ...