Splunk Enterprise Security

## Can I convert duration in minutes into days, hours, minutes Path Finder

Hi,

I have a final value in minutes, but I'd like to display this in a more user friendly manner, i.e;

1680 minutes = 1 Day, 4 Hours.

Any ideas how this could be done? Thanks.

Tags (1)
1 Solution Champion

Hi

Try this

``````| makeresults
| eval minutes=1680
| eval result = tostring(minutes*60, "duration")
| eval duration2=replace(result,"(\d*)\+*(\d+):(\d+):(\d+)","\1 days \2 hours \3 minutes \4 secs")
`````` Champion

Hi

Try this

``````| makeresults
| eval minutes=1680
| eval result = tostring(minutes*60, "duration")
| eval duration2=replace(result,"(\d*)\+*(\d+):(\d+):(\d+)","\1 days \2 hours \3 minutes \4 secs")
`````` Path Finder

Hi, is there a way to drop the days and tidy it up so that instead of;

0 days 1 hours 43 minutes 47 secs.1428571428578

it produces;

1 hour, 43 minutes, 47 seconds.

Thanks!! Ultra Champion

Do you just want to strip off "0 days", or do you want to multiply the number of days by 24 and add it to the hours?

Stripping of the "0 days" should be easy enough, just change the last line of that query to not print the days (remove the `\1 days`😞

`````` | eval duration2=replace(result,"(\d*)\+*(\d+):(\d+):(\d+)","\2 hours \3 minutes \4 secs")
`````` Path Finder

Probably need to multiply the number of days I guess. I need the total number of hours to jump to say, 28 hours, instead of 1 day, 4 hours.... if that makes sense Champion

Hi

try this

``````| makeresults
| eval minutes=1698
| eval result = tostring(minutes*60, "duration")
| rex field=result "((?P<day>\d+)\+){0,1}(?P<hour>\d{2}):(?P<min>\d{2}):(?P<sec>\d{2})"
| eval hour=if(day>0,((day*24))+hour,hour)
| eval result = hour." hours ".min." minutes ".sec." seconds"
| table result
`````` Builder

I made one adjustment in case you need the days to show up
If days are less than 1, there will be no value, so fillnull to 0

| makeresults
| eval minutes=1698
| eval result = tostring(minutes*60, "duration")
| rex field=result "((?P<day>\d+)\+){0,1}(?P<hour>\d{2}):(?P<min>\d{2}):(?P<sec>\d{2})"
| fillnull value=0 day
| eval result = day." days ".hour." hours ".min." minutes ".sec." seconds"
| table result

| makeresults
| eval minutes=111698
| eval result = tostring(minutes*60, "duration")
| rex field=result "((?P<day>\d+)\+){0,1}(?P<hour>\d{2}):(?P<min>\d{2}):(?P<sec>\d{2})"
| fillnull value=0 day
| eval result = day." days ".hour." hours ".min." minutes ".sec." seconds"
| table result Ultra Champion

That's what I was going to suggest as well 🙂 Path Finder

Thanks for the help. Path Finder

beautiful. Thanks 🙂 Path Finder

Perfect. Thanks. Path Finder

Sorry, me again. How would I tweak that if I wanted to drop the days from the output? so no mention of days, and just a total by hours, minutes, seconds? Thanks. *NEW* Splunk Love Promo!