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!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...