Splunk Search

Snap to previous Friday

jclemons7
Path Finder

Hello,

I have the following time modifier, which I was hoping would give me the previous Friday as a static date, but it doesn't for obvious reasons.

earliest=-7d@w5 latest=-7d@w6 | eval TimeStamp=strftime(strptime(timestamp, "%Y-%m-%dT%H:%M:%S"),"%m/%d/%Y %H") | dedup TimeStamp | table TimeStamp

What I'm trying to do is craft a query that will always pull the previous Friday (or whatever full weekday I chose).

Any help is greatly appreciated.

0 Karma

somesoni2
Revered Legend

If you're just looking to get the date, from today, for a specific weekday, you can try this run anywhere sample query. Just update the weekday filter in the where clause.

| gentimes start=-7 | table starttime | where strftime(starttime,"%a")="Fri" | eval timestamp=strftime(starttime,"%m/%d/%Y %H")
0 Karma

woodcock
Esteemed Legend

Try w5-7d@d and w6-7d@d

0 Karma

jclemons7
Path Finder

Thanks so much for your response,

I think this is similar to the problem I had before.. so, in my query I wanted previous Sunday let's say.. so using your syntax I wrote this:

earliest=@w0-7d latest=@w1-7d | eval TimeStamp=strftime(strptime(timestamp, "%Y-%m-%dT%H:%M:%S"),"%m/%d/%Y %H") | dedup TimeStamp | table TimeStamp

But that returns 3/27 for my date and what I'm really looking for would be 4/3 if run today (4/6) if that makes any sense..

0 Karma

woodcock
Esteemed Legend

OK, so do @w0@d and @w1@d.

0 Karma

jclemons7
Path Finder

Additionally.. if I run it today for Wednesday, I wouldn't want it to consider today and only return partial results.. I was looking for it to return last Wednesday..

I know in SQL this is tricky, but was hoping Splunk had something that would get me like 90% there.

0 Karma
Get Updates on the Splunk Community!

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 ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...