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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...