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!

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...

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 ...

Splunk App for Anomaly Detection End of Life Announcement

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...