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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...