Splunk Search

Compare date in search

twtyj
New Member

I have events containing field "Agent_Local_Time="9/19/2016 1:36:19 PM", I use EVAL to format the time "eval final_time=strftime(strptime(Agent_Local_Time,"%m/%d/%Y %l:%M:%S %p"),"%Y-%b-%d")" and also I EVAL start_time and end_time as below:
start_date=strptime("3/1/2016","%m/%d/%Y")
end_date=strptime("8/31/2016","%m/%d/%Y")

can i compare final_time between start_date and end_date like below:
| where final_time>start_time AND final_time<end_time

is there any solution if it can't.

thanks.

Tags (1)
0 Karma
1 Solution

somesoni2
Revered Legend

You can keep (at least temporarily) the format of final_time to epoch and then you can compare it with start_time and end_time, like this

...your search | eval final_time=strptime(Agent_Local_Time,"%m/%d/%Y %l:%M:%S %p") | evalstart_date=strptime("3/1/2016","%m/%d/%Y") | eval end_date=strptime("8/31/2016","%m/%d/%Y")
| where final_time>start_time AND final_time<end_time |eval final_time=strftime(final_time,"%Y-%b-%d")

View solution in original post

0 Karma

twtyj
New Member

thanks, it works now.

0 Karma

somesoni2
Revered Legend

You can keep (at least temporarily) the format of final_time to epoch and then you can compare it with start_time and end_time, like this

...your search | eval final_time=strptime(Agent_Local_Time,"%m/%d/%Y %l:%M:%S %p") | evalstart_date=strptime("3/1/2016","%m/%d/%Y") | eval end_date=strptime("8/31/2016","%m/%d/%Y")
| where final_time>start_time AND final_time<end_time |eval final_time=strftime(final_time,"%Y-%b-%d")
0 Karma
Get Updates on the Splunk Community!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...