Splunk Search

How to convert this string to a date?

nicocin
Path Finder

I'm trying to convert a string to a date.

The string looks like 2016-05-20T05:16:02.007+02:00

Tags (4)
0 Karma
1 Solution

javiergn
SplunkTrust
SplunkTrust

Try this:

| stats count
| fields - count
| eval timestamp = "2016-05-20T05:16:02.007+02:00"
| eval timestamp_epoch = strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%3N%z")

View solution in original post

javiergn
SplunkTrust
SplunkTrust

Try this:

| stats count
| fields - count
| eval timestamp = "2016-05-20T05:16:02.007+02:00"
| eval timestamp_epoch = strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%3N%z")

nicocin
Path Finder

Hmm I get something like this "1463714162.007000"

0 Karma

javiergn
SplunkTrust
SplunkTrust

Yes, that's epoch time and that's what Splunk uses internally to represent dates and times.

http://www.epochconverter.com
https://en.wikipedia.org/wiki/Unix_time

What were you planning to do with that timestamp after that?
Now that it's in the right format you can use strftime and plenty or other functions to work with it. For example:

| eval date = strftime(timestamp_epoch, "%Y-%m-%d")

nicocin
Path Finder

Ahh ok, working great like this.

Thank you!

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...