Dashboards & Visualizations

How do I count time differently than 00:00 ~ 24:00?

hyungjoon
New Member

Question)
If my store is open through 1pm~2am and I want to see how many chickens I sold on one day, Splunk would count the
chickens I sold from 12am~2am to the next day and count the chickens I sold the day before.

I want to make a line chart of this but the calculations are wrong because of this.

Can anybody help?

0 Karma
1 Solution

nswondem
Path Finder

Hi hyngjoon,

The goal would be to identify whether an event occurred yesterday or today, then compare the datehours.

  1. Calculate the start of yesterday
  2. Calculate the start of today
  3. Get the datehour using strftime
  4. Convert the hr to a number (since it is a string)
  5. Determine whether the event time is yesterday and the hour is after 12pm OR whether the event time is today and the hour is before 2am.

Nadine
...
| eval yesterday=relative_time(now(), "-1d@d")
| eval today=relative_time(now(), "@d")
| eval hr=strftime(_time, "%H")
| eval hr=tonumber(hr)
| where (_time >= yesterday AND hr > 12) OR (_time >= today AND hr <=2)

View solution in original post

0 Karma

nswondem
Path Finder

Hi hyngjoon,

The goal would be to identify whether an event occurred yesterday or today, then compare the datehours.

  1. Calculate the start of yesterday
  2. Calculate the start of today
  3. Get the datehour using strftime
  4. Convert the hr to a number (since it is a string)
  5. Determine whether the event time is yesterday and the hour is after 12pm OR whether the event time is today and the hour is before 2am.

Nadine
...
| eval yesterday=relative_time(now(), "-1d@d")
| eval today=relative_time(now(), "@d")
| eval hr=strftime(_time, "%H")
| eval hr=tonumber(hr)
| where (_time >= yesterday AND hr > 12) OR (_time >= today AND hr <=2)

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...