Splunk Search

Adding seconds to _time

ChhayaV
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

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

sowings
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?

ChhayaV
Communicator

already tried

0 Karma

kristian_kolb
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

ChhayaV
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

sowings
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

Ayn
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

ChhayaV
Communicator

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

index=tm_idx host="server" index=tm_idx 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

Ayn
Legend

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

0 Karma

ChhayaV
Communicator

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

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...