Splunk Search

how to compare dates outside of the default date field

mikefoti
Communicator

While trying to figure out where a query like the following fails...

cert_endDate>12/5/2011 AND certEnd_date<12/7/2011

It dawned on me that the search engine only recognizes my field value as a string of numbers and slashes. Searching thru other questions and answers lead me to the Convert funtion. But It seems overly complicated... making me wonder if I've missed somethin far simpler.
My question is.. if my field values look like this:

 cert_EndDate=12/6/2016

... how can I get the search engine to treat/evaluate/recognize them as actual dates?

Tags (1)
1 Solution

Ayn
Legend

Convert the field to epoch values (seconds since 1 Jan 1970) and use those for comparison with another time in epoch:

... | eval cert_EndDate_epoch=strptime(cert_EndDate,"%m/%d/%Y")
    | where cert_EndDate_epoch<strptime("12/6/2016", "%m/%d/%Y")

View solution in original post

Ayn
Legend

Convert the field to epoch values (seconds since 1 Jan 1970) and use those for comparison with another time in epoch:

... | eval cert_EndDate_epoch=strptime(cert_EndDate,"%m/%d/%Y")
    | where cert_EndDate_epoch<strptime("12/6/2016", "%m/%d/%Y")

mikefoti
Communicator

Thanks, I guess its not that complicated after all.

0 Karma
Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

New Release | Splunk Cloud Platform 10.1.2507

Hello Splunk Community!We are thrilled to announce the General Availability of Splunk Cloud Platform 10.1.2507 ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

&#x1f5e3; You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...