Getting Data In

How do we specify same day last week

xvxt006
Contributor

Hi,

i want to compare the traffic from today to the traffic from the same day a week back.

in the time range i have -7d@h in the from filed and left empty in the to field. Also my query is like this ....| stats count by date_hour

I don't think i am getting right stats. When i verified the same search query using custom time frame (for the same day last week) i am getting different counts. Any suggestions?

Tags (1)
1 Solution

carasso
Splunk Employee
Splunk Employee

Comparing week-over-week results used to a pain in Splunk, with complex date calculations. No more. Now there is a better way.

I wrote a convenient search command called "timewrap" that does it all, for arbitrary time periods.

... | timechart count span=1h | timewrap w 

That's it!

If you want to limit it to a specific day of the week, add:

... | where strftime(_time, "%A") == "Wednesday"

http://apps.splunk.com/app/1645/

View solution in original post

MayankChandra
Engager

@kristian_kolb Suppose we want splunk to evaluate yesterday's day on its own and we dont mention specific day of the week like "Wednesday"  and then use yesterday's day of week to compare data with same day of week for last 2 weeks, how we can achieve that?

0 Karma

carasso
Splunk Employee
Splunk Employee

Comparing week-over-week results used to a pain in Splunk, with complex date calculations. No more. Now there is a better way.

I wrote a convenient search command called "timewrap" that does it all, for arbitrary time periods.

... | timechart count span=1h | timewrap w 

That's it!

If you want to limit it to a specific day of the week, add:

... | where strftime(_time, "%A") == "Wednesday"

http://apps.splunk.com/app/1645/

xvxt006
Contributor

Thank you Kristian for your help. This is very useful.

0 Karma

kristian_kolb
Ultra Champion

well, date_hour can be wrong! Especially if you're pulling logs from more than one TZ.

_time gets the value adjusted for TZ - what you see to the left of each event.
date_hour is the hour from within the event itself.

With _time you can make searches like "what happened in the last 15 mins, across all timezones"
With date_* you can with a single search that asks questions like "who was logging on after 8.00, in their respective TZ". (Dont forget to use a wide enough timespan in the search though).

Other than that, have you looked at the DeploymentMonitor app. It contains searches that compare statistics for 'now' and 'same day/hour last week'. You could possibly gain some insights from looking at them.

Also, there is a blog post on the subject;

http://blogs.splunk.com/2012/02/19/compare-two-time-ranges-in-one-report/

Hope this helps,

Kristian

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Make Your Machine Data AI-Ready in Splunk

Every team is getting ready for AI agents.   Thursday, November 12, 2026  |  11AM  PST / 2PM EST   ...

Splunk Asynchronous Forwarding Explained

Splunk asynchronous forwarding is often misunderstood as simply setting autoLBVolume. That is not quite right. ...

How to Monitor AI Agents with Splunk Agent Observability

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...