Splunk Search

Time format

shugup2923
Path Finder

I have time field which have values such as 9AM-10PM, 10:00AM-11:00PM, I want to change 9AM-10PM to 9:00AM-10:00 PM, to normalize field in sameformat.

I tired strftime(strptime(time_field,"%H%p-%H%p"),"%H:%M%p-%H%:%M%p") 

But its not working, I also tried convert() and fieldformat but no luck. Any idea how can I achieve this ?

Labels (1)
0 Karma
1 Solution

manjunathmeti
SplunkTrust
SplunkTrust

hi @shugup2923,

You can use replace function.

| eval time=if(like(time, "%:00%"), time, replace(replace(time, "AM", ":00AM"), "PM", ":00PM"))

View solution in original post

shugup2923
Path Finder

| eval timing=case(Match(timing, "\d*:\d*\w*-\d*:\d*\w*"), timing,Match(timing, "\d*:\d*\w*-\d*\w*"), replace(timing,"PM",":00PM"),Match(timing, "\d*\w*-\d*:\d*\w*"), replace(timing,"AM",":00AM"),true(), replace(replace(timing, "AM", ":00AM"), "PM", ":00PM"))

0 Karma

shugup2923
Path Finder

Perfect this worked, just I did small modification - used match instead of like as there are some other values as well. Approach is very useful

0 Karma

manjunathmeti
SplunkTrust
SplunkTrust

hi @shugup2923,

You can use replace function.

| eval time=if(like(time, "%:00%"), time, replace(replace(time, "AM", ":00AM"), "PM", ":00PM"))
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...