Splunk Search

How to convert duration in seconds to [h]:mm:ss?

auaave
Communicator

Hi,

I have a table with duration in seconds, how can I convert it to [h]:mm:ss? I want it to count the number of hours even if it is more than 1 day. Thanks!

Here is my query.

| dedup IDEVENT
| where _time>relative_time(now(),"-4w@w")
| bin _time span=1w
| stats sum(DURATION) as eventduration by DESCRIPTION _time
0 Karma
1 Solution

harsmarvania57
Ultra Champion

Hi

Can you please try | eval time=strftime(_time, "%H:%M:%S") or you can try | eval time=tostring(_time,"duration")

So your query will be

 | dedup IDEVENT
 | where _time>relative_time(now(),"-4w@w")
 | bin _time span=1w
 | stats sum(DURATION) as eventduration by DESCRIPTION _time
 | eval time=strftime(_time, "%H:%M:%S")

and with second approach

 | dedup IDEVENT
 | where _time>relative_time(now(),"-4w@w")
 | bin _time span=1w
 | stats sum(DURATION) as eventduration by DESCRIPTION _time
 | eval time=tostring(_time,"duration")

View solution in original post

harsmarvania57
Ultra Champion

Hi

Can you please try | eval time=strftime(_time, "%H:%M:%S") or you can try | eval time=tostring(_time,"duration")

So your query will be

 | dedup IDEVENT
 | where _time>relative_time(now(),"-4w@w")
 | bin _time span=1w
 | stats sum(DURATION) as eventduration by DESCRIPTION _time
 | eval time=strftime(_time, "%H:%M:%S")

and with second approach

 | dedup IDEVENT
 | where _time>relative_time(now(),"-4w@w")
 | bin _time span=1w
 | stats sum(DURATION) as eventduration by DESCRIPTION _time
 | eval time=tostring(_time,"duration")

auaave
Communicator

@harsmarvania57 , thanks! The second approach works! 🙂

0 Karma

harsmarvania57
Ultra Champion

@auaave, Glad to hear that it worked, please accept my answer and upvote it. 🙂

0 Karma

p_gurav
Champion

Hi Auaave,

You can use strftime function using eval. For eg.
eval eventduration=strftime(eventduration,"%H:%M:%S")

0 Karma

auaave
Communicator

@p_gurav, thanks for your reply. 🙂

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