Splunk Search

Convert month field from csv in different format?

pgadhari
Builder

My csv file has  "month" field and the values are as below :

 

2020-10
2020-09
2020-08
2020-07
2020-06
2020-05
2020-04
2020-03
2020-02
2020-01

 

 

I want to convert the months from number to Jan, Feb, Mar, Apr and so on... I tried using strptime, but that is not working. I want to show it as 2020-Jan, 2020-Feb, 2020-Mar... 

Please help , below is my query :

 

index=azure sourcetype=azure_total_cost source="C:\total_cost\\azure_total_cost_by_year.csv" month!="month" | eval mymonth=strftime(month, "%Y-%b")

 

 

 

 

Labels (2)
0 Karma
1 Solution

renjith_nair
Legend

Add a dummy "day" to the month and try converting it

|makeresults|eval month="2020-10"|eval nMonth=month."-01"|eval formattedMonth=strftime(strptime(nMonth,"%Y-%m-%d"),"%Y-%b")

 

---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

pgadhari
Builder

Yes @renjith_nair . I am able to resolve the issue with the above query. Thank you very much for immediate respnose.

renjith_nair
Legend

Add a dummy "day" to the month and try converting it

|makeresults|eval month="2020-10"|eval nMonth=month."-01"|eval formattedMonth=strftime(strptime(nMonth,"%Y-%m-%d"),"%Y-%b")

 

---
What goes around comes around. If it helps, hit it with Karma 🙂
Get Updates on the Splunk Community!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...