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!

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

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...