Splunk Search

Adding seconds to _time

Communicator

hi,

I want to add some seconds in the current _time.
Is there any build in function for it?

e.g_time=23:03:39.022
after adding 4.90 seocnds it should be 23:03:43.936

Thanks

0 Karma

Legend

_time is actually in epoch format, Splunk just converts the format automatically before showing it to you so that it's human readable. So, to add 4 seconds, just do eval _time=_time+4.

Note that this is purely a search-time operation - if you want to do this at index-time the problem is much more complex because functions for performing arithmetic etc are not available.

Splunk Employee
Splunk Employee

This works, and gives milliseconds:

convert timeformat="%Y/%m/%d %H:%M:%S.%3N" ctime(_time) AS timestr

What did you try that didn't work?

Communicator

already tried

0 Karma

Ultra Champion

shouldn't the expected outcome be 23:03:39.846 ?

and for strftime/strptime, %3N, %6N are the variables for milli- and microseconds, respectively.

http://docs.splunk.com/Documentation/Splunk/5.0.5/SearchReference/Commontimeformatvariables

0 Karma

Communicator

hi
input time: 23:03:43.936
after subtracting 4.09
expected output time: 23:03:39.022

but output time is 23:03:39

i gave %ms after %S but not working and when i export it to CSV time column is not proper it show ### in the column

0 Karma

Splunk Employee
Splunk Employee

Your time format output truncates to seconds. You'll need to add some placeholder in the format string for milli / microseconds.

0 Karma

Legend

Explain more clearly. What do you mean by not being able to see milliseconds? What are you expecting to see, and what are you not seeing?

0 Karma

Communicator

got it ..but i am not able to see milliseconds

index=tmidx host="server" index=tmidx host="server" "finished executing normally" | rex field=raw "(?i)Process\s(\"|\"})(?\w+)" | rex field=raw "elapsed\stime\s(?\w+.\w+)\sseconds" | eval time=_time-myduration| convert timeformat="%m/%d/%Y %H:%M:%S" ctime(time) as timestr |table _time timestr _raw myduration

this is my search

0 Karma

Legend

Yup. Epoch is just seconds, so add how many seconds you want.

0 Karma

Communicator

if it is 200 seconds then resulted output time should also have minutes modified

0 Karma