Splunk Search

Convert time from AM/PM to 24 Hour format

chandra61446
New Member
index=* "please type serach keyword" host=xyz*
| rex field=_raw "^(?:[^ \n]* ){2}(?P\d+:\d+):\d+\s+\w+\s+\w+:\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+\d+\s+(?P\d+:\d+)"]
| dedup host
| convert timeformat="%H:%M:%S" ctime(ServerTime) AS ST
| table ServerTime ST DeviceSyncTime

alt text

ServerTime shows in AM/PM format and DeviceSyncTime shows in 24 hour format. How do I change the ServerTime field value to the 24 hour format?

Note I don't want to have _time anywhere..

0 Karma
1 Solution

alemarzu
Motivator

Hi there chandra, try with this.

| eval time24hs=strftime(ServerTime, "%H:%M:%S")

Hope it helps.

View solution in original post

0 Karma

somesoni2
Revered Legend

Where are you extracting ServerTime field and what is the format of the value (sample logs will be helpful)?

0 Karma

chandra61446
New Member

Below id raw data

[10A8:0564-151C] 03/01/2016 09:58:22 PM Traveler: The last successful device sync was on Tue Mar 01 21:58:21 EST 2016.

I am picking 09:58 as ServerTime abd 21:58 as DeviceSyncTime

Now like to ServerTime to converted into 24hours format

0 Karma

alemarzu
Motivator

Hi there chandra, try with this.

| eval time24hs=strftime(ServerTime, "%H:%M:%S")

Hope it helps.

0 Karma

chandra61446
New Member

This one worked

| eval epochtime=strptime(Dtime, "%H:%M:%S")| eval DSyncTime=strftime(epochtime, "%I:%M:%S")

0 Karma

chandra61446
New Member

It did not help .. Below id raw data

[10A8:0564-151C] 03/01/2016 09:58:22 PM Traveler: The last successful device sync was on Tue Mar 01 21:58:21 EST 2016.

I am picking 09:58 as ServerTime abd 21:58 as DeviceSyncTime

Now like to ServerTime to converted into 24hours format

0 Karma

alemarzu
Motivator

Use _time instead ServerTime, like this.

| eval time24hs=strftime(_time, "%H:%M:%S")
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 ...