Splunk Search

Need to filter out latest one year date for the particular field in table

Ashwini_5
Explorer

Hello Experts, 

 

Kindly help to filter out latest one year date for the particular field. 

For ex:  index="abc" sourcetype="xyz" 
|table ID, COMPLETION_DATE, LEARNING_ITEM_ID, LEARNING_ITEM_TITLE, TARGET_DATE

Here I just need to filter out who has completed within last one year in the completion date . Actually, Completion date showing for last five years .. But I just need to filter out only for past year without mentioning any date in query. I am wondering if we can use latest command .. Kindly help  

 

Labels (2)
Tags (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

To find dates within the past year, first convert the date into epoch form then compare the result to the current time using relative_time().

index="abc" sourcetype="xyz" 
| eval CD=strptime(COMPLETION_DATE, "<<insert format string here>>")
| where CD >= relative_time(CD, "-1year")
| table ID, COMPLETION_DATE, LEARNING_ITEM_ID, LEARNING_ITEM_TITLE, TARGET_DATE

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

To find dates within the past year, first convert the date into epoch form then compare the result to the current time using relative_time().

index="abc" sourcetype="xyz" 
| eval CD=strptime(COMPLETION_DATE, "<<insert format string here>>")
| where CD >= relative_time(CD, "-1year")
| table ID, COMPLETION_DATE, LEARNING_ITEM_ID, LEARNING_ITEM_TITLE, TARGET_DATE

 

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...