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!

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to Officially Supported Splunk ...