Splunk Search

Week number and Month/Day of the begining of that week

wpreston
Motivator

I report on a count of events by week number, it displays like this:

Week Number         Count
-----------         -----
01                  15
02                  35
03                  35
...

I use strftime(_time, "%v") to get the week number. How can I also display the calendar month and day of the first day of each week in the report? Ideally, the report would look like this:

Week Number         Week Begin         Count
-----------         ----               -----
01                  12/31              15
02                  01/07              35
03                  01/14              35
...
Tags (1)
1 Solution

lguinn2
Legend

try this

| eval Day1ofWeek = strftime(relative_time(_time,"@w0"),"%m/%d")

will be the Sunday. If you want the Monday, use this

| eval Day1ofWeek = strftime(relative_time(_time,"@w1"),"%m/%d")

View solution in original post

lguinn2
Legend

try this

| eval Day1ofWeek = strftime(relative_time(_time,"@w0"),"%m/%d")

will be the Sunday. If you want the Monday, use this

| eval Day1ofWeek = strftime(relative_time(_time,"@w1"),"%m/%d")

wpreston
Motivator

Exactly what I was looking for, thanks!

0 Karma

blhuynh
Explorer

Does this work in Splunk 6.1.3? I cannot get the additional column to display when I append the piped statement to my search strings.

0 Karma

somesoni2
Revered Legend

It does work on 6.1.3. Above statement requires field _time to be available before this command. What is your current query?

0 Karma

blhuynh
Explorer

I have a set of data that I am averaging weekly using eval week=strftime(_time,"%Y-%U"). I then display this using chart values(foo) by week, bar.

However, I'd like to replace the week column with the date of the Monday of that week when it is displayed in the table. I would still like the data to be sorted by week still, but I do not want the week number to be displayed, only for that Monday of that week to be displayed. Thanks.

I wanted to generated a the Day1ofWeek column and appendcols to my search query but just generating a Day1ofWeek column with my query doesn't work.

What do you mean by "requires field _time to be available before this command"? Does that mean that I cannot use _time in my eval week statement?

0 Karma

somesoni2
Revered Legend

The answer by Lisa uses field _time (epoch format) to generate the Day1ofWeek, which is not available after your chart command, you can't use it directly. What I would suggest is to use something like this

your base search |  eval week=relative_time(_time,"@w1")| chart  values(foo) by week,bar| eval week=strftime(week,"%Y-%m-%d  %a") 

It will be sort ascending order of the date/week.

0 Karma

blhuynh
Explorer

That worked! Thanks so much especially with the prompt responses.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...