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!

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2025 SplunkTrust is officially open! If you ...

Splunk Answers Content Calendar, June Edition II

Get ready to dive into Splunk Dashboard panels this week! We'll be tackling common questions around ...

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

This is the third post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...