Splunk Search

Time format & Duration Calc

zoebanning
Path Finder

Hello Splunk Community, 

Can anyone help me build a query based on the below;

I want to convert a field (Fri Oct 8 23:15:05 AEDT 2021) into time format & then calculate the duration by subtracting the end time by the start time. 

Appreciate your help 🙂

Labels (1)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@zoebanning 

You can achieve this by using strptime function and tostring function.

 

Can you please try this?

 

YOUR_SEARCH
|eval start_epoch=strptime(start_time,"%a %b %d %H:%M:%S %Z %Y"),end_epoch=strptime(end_time,"%a %b %d %H:%M:%S %Z %Y"), diff_in_sec=end_epoch-start_epoch,duration=tostring(diff_in_sec,"duration")

 

My Sample Search :

| makeresults 
| eval start_time="Fri Oct 8 23:15:05 AEDT 2021",end_time="Fri Oct 8 23:20:05 AEDT 2021"
|eval start_epoch=strptime(start_time,"%a %b %d %H:%M:%S %Z %Y"),end_epoch=strptime(end_time,"%a %b %d %H:%M:%S %Z %Y"), diff_in_sec=end_epoch-start_epoch,duration=tostring(diff_in_sec,"duration")

References:

Conversion functions

Date and Time functions

Date and time format variables

I hope this will help you.

Thanks
KV
▄︻̷̿┻̿═━一   😉

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

View solution in original post

zoebanning
Path Finder

Thank you Karma! This was exactly what I needed, appreciate your help 😀

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@zoebanning 

You can achieve this by using strptime function and tostring function.

 

Can you please try this?

 

YOUR_SEARCH
|eval start_epoch=strptime(start_time,"%a %b %d %H:%M:%S %Z %Y"),end_epoch=strptime(end_time,"%a %b %d %H:%M:%S %Z %Y"), diff_in_sec=end_epoch-start_epoch,duration=tostring(diff_in_sec,"duration")

 

My Sample Search :

| makeresults 
| eval start_time="Fri Oct 8 23:15:05 AEDT 2021",end_time="Fri Oct 8 23:20:05 AEDT 2021"
|eval start_epoch=strptime(start_time,"%a %b %d %H:%M:%S %Z %Y"),end_epoch=strptime(end_time,"%a %b %d %H:%M:%S %Z %Y"), diff_in_sec=end_epoch-start_epoch,duration=tostring(diff_in_sec,"duration")

References:

Conversion functions

Date and Time functions

Date and time format variables

I hope this will help you.

Thanks
KV
▄︻̷̿┻̿═━一   😉

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

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