Getting Data In

How to change date format multiple time

fatanyk
Explorer

Hello,

I'm trying to change my date format two times because i want to sort to order my month from January to December.

I've been trying this search but the field newPeriode2 isn't showing any results :

| eval newPeriode = strftime(strptime(Période,"%Y-%m-%d"),"%m-%Y")
| sort newPeriode
| eval newPeriode2 = strftime(strptime(newPeriode,"%m-%Y"), "%B-%Y")

this is what it looks like. I want my newPeriode2 looks like : January-2022 etc...

fatanyk_0-1664195890878.png

Thanks for your help ! 🙂

Labels (1)
0 Karma
1 Solution

isoutamo
SplunkTrust
SplunkTrust

Hi

just convert it to epoch and then sort

| eval newPeriode = strptime(Période,"%Y-%m-%d %H:%M:%S")
| sort newPeriode
| eval newPeriode2 = strftime(newPeriode, "%B-%Y")

As epoch is a integer it will sort time correctly. Then just convert it back to you desired format.

r. Ismo

View solution in original post

isoutamo
SplunkTrust
SplunkTrust

Hi

just convert it to epoch and then sort

| eval newPeriode = strptime(Période,"%Y-%m-%d %H:%M:%S")
| sort newPeriode
| eval newPeriode2 = strftime(newPeriode, "%B-%Y")

As epoch is a integer it will sort time correctly. Then just convert it back to you desired format.

r. Ismo

fatanyk
Explorer

Thank you for your help ! 

This work !

0 Karma
Get Updates on the Splunk Community!

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...