Splunk Search

How can I convert "2016-12-17T00:30:00.000+0000" to epoch time?

m7787579
New Member

How can i convert 2000-12-17T00:30:00.000+0000 to epoch time?

I tried using
1.) eval _time= strptime(_time,"%Y-%m-%dT%H:%M:%S.%3N%z")
2.) eval _time=strptime(_time,"%Y-%m-%dT%H:%M:%S")

I would like to understand how can i convert it into epoch time using strptime function?

0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi m7787579,
_time is already in epochtime, you can test this with an easy example

index=_internal | head 1 | eval newdate=strptime("2000-12-17T00:30:00.000+0000","%Y-%m-%dT%H:%M:%S.%3N%z") | eval diff=_time-newdate | table _time newdate diff

or renaming _time in your searches: it's showed in epochtime.

The command | eval another_time= strptime(another_time,"%Y-%m-%dT%H:%M:%S.%3N%z") is useful to convert another time in epochtime.

Bye.
Giuseppe

View solution in original post

0 Karma

woodcock
Esteemed Legend

This makes test event:

| makeresults
| eval time="2000-12-17T00:30:00.001+0000"

This is the solution:

| eval _time=strptime(time,"%Y-%m-%dT%H:%M:%S.%3N%z")
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi m7787579,
_time is already in epochtime, you can test this with an easy example

index=_internal | head 1 | eval newdate=strptime("2000-12-17T00:30:00.000+0000","%Y-%m-%dT%H:%M:%S.%3N%z") | eval diff=_time-newdate | table _time newdate diff

or renaming _time in your searches: it's showed in epochtime.

The command | eval another_time= strptime(another_time,"%Y-%m-%dT%H:%M:%S.%3N%z") is useful to convert another time in epochtime.

Bye.
Giuseppe

0 Karma

niketn
Legend

You have asked question to convert String time to epoch.... However, you are applying the same on _time field which should already be epoch.

Following is a run anywhere example with string time converted to epoch. I have used replace to remove + sign and then %6N.

| makeresults
| eval time="2000-12-17T00:30:00.000+0000"
| replace "+" with "" in time
| eval time=strptime(time,"%Y-%m-%dT%H:%M:%S.%6N")

Following worked for me without replace as well.

| makeresults
| eval time="2000-12-17T00:30:00.000+0000"
| eval time=strptime(time,"%Y-%m-%dT%H:%M:%S.%6N")
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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