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!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

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

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...