Splunk Search

Search showing time in months in alphabetic order

kml_uvce
Builder

My search showing alphabetic order in months(like chart is in this order (dec,feb,jan, nov)

|eval month=strftime(strptime(lsCDR_endTime,"%Y-%m-%d"),"%b") | chart sum(lsCDR_duration) as Duration(in sec) over month

Can someone please help me on this ?

Tags (1)
0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

You can use the fieldformat command to retain numeric sort order, while changing how a field's value is displayed. You will need to rewrite your search, e.g."

<search> 
 | eval month=strftime(strptime(lsCDR_endTime,"%Y-%m-%d"),"%m")
 | fieldformat month=strftime(strptime(lsCDR_endTime,"%Y-%m-%d"),"%b")
 | chart sum(lsCDR_duration) as Duration(in sec) over month

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee

You can use the fieldformat command to retain numeric sort order, while changing how a field's value is displayed. You will need to rewrite your search, e.g."

<search> 
 | eval month=strftime(strptime(lsCDR_endTime,"%Y-%m-%d"),"%m")
 | fieldformat month=strftime(strptime(lsCDR_endTime,"%Y-%m-%d"),"%b")
 | chart sum(lsCDR_duration) as Duration(in sec) over month

Ayn
Legend
<search> | eval _month_num=strftime(strptime(lsCDR_endTime,"%Y-%m-%d"),"%m") | eval month=strftime(lsCDR_endTime,"%Y-%m-%d"),"%b") | stats sum(lsCDR_duration) as "Duration(in sec)" by _month_num,month | sort _month_num
0 Karma

lguinn2
Legend

How about

| eval month=strftime(strptime(lsCDR_endTime,"%Y-%m-%d"),"%m") | chart sum(lsCDR_duration) as "Duration(in sec)" over month

which gives the month as a decimal number instead of the name of the month.

0 Karma

kml_uvce
Builder

but I want to show as month name in output

0 Karma
Get Updates on the Splunk Community!

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...