Splunk Search

date strftime convert and show last 4 days

felipesewaybric
Contributor

Hey guys, i have | eval Date=strftime(strptime(data,"%Y/%m/%d"),"%m/%d") returning

07/02
07/01
06/30
06/29
06/28

but i want to receive only the last 4 days.

07/02
07/01
06/30
06/29

The data is in a lookup_table csv

Tags (1)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

String comparisons are usually bad news. Consider this instead:

| where strptime(data,"%Y/%m/%d") >= relative_time(now(), "-4d")

That way the comparison is done using numbers / epoch time, so there's no ambiguity in case your date formatting requirements change.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

String comparisons are usually bad news. Consider this instead:

| where strptime(data,"%Y/%m/%d") >= relative_time(now(), "-4d")

That way the comparison is done using numbers / epoch time, so there's no ambiguity in case your date formatting requirements change.

felipesewaybric
Contributor

ok, i think i found what i need:

| where Date >= strftime(relative_time(now(), "-4d"), "%m/%d")

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...