Splunk Search

How to convert a date time field to epoch time?

splunker9999
Path Finder

Hi,

I am looking to format my current time to epoch time (as we need to calculate some math function on time)

Time format for incidentEndTimeStr looks like this: 4/11/16 2:52

And used the eval command and strptime function below to change the format, but it doesn't work. Can you please assist?

eval incidentEndTime = strptime(incidentEndTimeStr, "%m/%d/%Y %I:%M")

OR

eval incidentEndTime = strptime(incidentEndTimeStr, "%m/%d/%Y %H:%M")

Thanks

0 Karma

gcusello
SplunkTrust
SplunkTrust

The problem is the year that it's composed by only two digits, so you have to use "%y" instead "%Y".
Bye.
Giuseppe

gcusello
SplunkTrust
SplunkTrust

if you're satisfied of the answer, please, accept the answer.
Bye.
Giuseppe

0 Karma

sundareshr
Legend

Try this

strptime(incidentEndTimeStr, "%-m/%-d/%y %-H:%-M") 

Here's a working sample

| makeresults | eval x="4/11/16 2:52" | eval t=strptime(x, "%-m/%-d/%y %-H:%-M") | eval z=strftime(t, "%-m/%-d/%y %-H:%-M") | table x t z
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 ...