Splunk Search

Splunk date comparison

mcamilleri
Path Finder

I need to be able to search for log entries with a specific start date, which has nothing to do with _time. The format is, for example, Start_Date: 08/26/2013 4:30 PM.

I need to add a condition in my search to specify the date, but not the time. I tried strptime and strftime unsuccessfully.

For example, I tried converting start date to a string (without time) and compare it to another string:

"08/26/2013"=strftime(Start_Date, "%d/%m/%Y")

This didn't work either:

 "08/26/2013"=strftime(strptime(Start_Date "%d/%m/%Y %I:%M %p"), "%d/%m/%Y")

Any ideas how to solve this?

1 Solution

kristian_kolb
Ultra Champion

If Start_Date is an extracted field you can just add it to the search in a key=value format, e.g;

host=blah sourcetype=bleh Start_Date=08/26/2013*

If it is not an extracted field, and you do not wish it to be, you can extract within the search first;

host=blah sourcetype=bleh | rex "Start_Date:\s(?<Start_Date>\S+)" | search Start_Date=06/26/2013*

Your use of strftime/strptime is not correct. Those two are functions of eval.

Hope this helps,

K

View solution in original post

0 Karma

rturk
Builder

If you want to use comparison operators instead of just making sure the string is equal to "08/26/2013 4:30 PM" (e.g. "return all events that have a start date after 09/24/2012"), you will need to convert the time into epoch seconds.

<base search> | eval start-epoch=strptime(Start_Date, "%m/%d/%Y %I:%M %p")

This will give you a new field start-epoch that may be used for comparison purposes.

NOTE: This assumes you have a field called Start_Date. If you do not, you will need to extract the date similarly to how kristian.kolb did in the other answer provided.

Hope this helps! 🙂

References:

kristian_kolb
Ultra Champion

If Start_Date is an extracted field you can just add it to the search in a key=value format, e.g;

host=blah sourcetype=bleh Start_Date=08/26/2013*

If it is not an extracted field, and you do not wish it to be, you can extract within the search first;

host=blah sourcetype=bleh | rex "Start_Date:\s(?<Start_Date>\S+)" | search Start_Date=06/26/2013*

Your use of strftime/strptime is not correct. Those two are functions of eval.

Hope this helps,

K

0 Karma

mcamilleri
Path Finder

Thanks! Start_Date=08/26/2013* works perfectly.

0 Karma

royimad
Builder

Use
search sourcetype="comparison" | eval existing_date=functions()
instead of comparing between 2 different dates of your search solve
evaluation function instead of equal sign, 2 different dates can not be equal try to use your existing dates to be compatible with your start_date format

Hope this will help.

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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...