Dashboards & Visualizations

How to extract the dates in order in a dashboard

Deprasad
Path Finder

I have a query which extracts counts for last 30 days. But the dates are not in proper order in result.

index = *** "search phrase" | stats count by date_mday | rename date_mday as Date

If i make a search today for last 30 days, the result should be in the below order .

01/18, 19, 20 .......... 02/16,02/17.

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

The date_mday field contains a single integer representing the day of the month on which the event occurred. Since there is no month information in the field, it's not reasonable to expect the month to be considered when sorting. Try sorting by _time, instead.

index=foo "search phrase" | bin span=1d _time | stats count by _time | rename _time as Date | fieldformat Date = strptime(Date, "%m/%d")
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

The date_mday field contains a single integer representing the day of the month on which the event occurred. Since there is no month information in the field, it's not reasonable to expect the month to be considered when sorting. Try sorting by _time, instead.

index=foo "search phrase" | bin span=1d _time | stats count by _time | rename _time as Date | fieldformat Date = strptime(Date, "%m/%d")
---
If this reply helps you, Karma would be appreciated.

efavreau
Motivator

Glad this is working for you, @Deprasad! Please remember to accept the answer, so this can help others too.

###

If this reply helps you, an upvote would be appreciated.
0 Karma

Deprasad
Path Finder

Thanks..! This is working, however the date field is in epoch format.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

It's converted in my updated answer.

---
If this reply helps you, Karma would be appreciated.
0 Karma

Deprasad
Path Finder

strptime(Date, "%m/%d") gave a blank result for Date. Gone through Splunk documentation and found for epoch time conversion the command is strftime(x,y).

Thanks for the help..!!

0 Karma
Get Updates on the Splunk Community!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...