Splunk Search

How do I convert year, month, day, hour, minute, seconds to seconds?

WXY
Path Finder

Now, I want to get the time interval

For example:

between 2018/5/31 8:25:45 and 2018/5/31 8:25:47 ,the time interval is 2s

What should I do?

alt text

Tags (3)
0 Karma

niketn
Legend

[UPDATED]

If the requirement is to convert seconds to Days Hour Minute Second format tostring() evaluation conversion function can be used.


@WXY, please try the following run anywhere search which generates one sample event with fields StartTime and EndTime ( |makeresults till eval StartTime="2018/5/31 8:25:45"... generates dummy Date values as per the question).

| makeresults
| fields - _time
| eval StartTime="2018/5/31 8:25:45", EndTime="2018/5/31 8:25:47"
| eval StartTime=strptime(StartTime,"%Y/%m/%d %H:%M:%S"),EndTime=strptime(EndTime,"%Y/%m/%d %H:%M:%S")
| eval duration=EndTime-StartTime
| fieldformat StartTime=strftime(StartTime,"%Y/%m/%d %H:%M:%S")
| fieldformat EndTime=strftime(EndTime,"%Y/%m/%d %H:%M:%S")

Pipe the following after | eval duration to convert to Days+ HH:MM:SS format:

 | eval durationString=tostring(duration,"duration")
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...