Splunk Search

Convert Zulu time to epoch

landzaat
Explorer

Some Windows events report date/time in zulu format: “‎2013‎-‎03‎-‎27T21:00:32.950000000Z”. I want to convert to epoch. Tried “

eval pt1=strptime(Previous_Time,"%Y-%m-%dT%H:%M:%S.%9NZ")

and some variants. Unfortunately no result. I am obviously overlooking something. Who knows what?

0 Karma

Aether
Engager

This solution doesn't appear to account for timezone, which Splunk automatically adjusts for. By adding a % before the Z, Splunk will not perform this adjustment, which unless you have your timezone set as GMT you dont want (this assumes its ACTUALLY zulu time).

Assuming you dont need to do the hyphen replacement, you can also shorthand the format to "%FT%T.%5N%Z"

The solution thus becomes:
eval time = strptime("2013-03-27T21:00:32.950000000Z", "%FT%T.%5N%Z")

or
eval time = strptime("2013-03-27T21:00:32.950000000Z", "%Y-%m-%dT%H:%M:%S.%9N%Z")

martin_mueller
SplunkTrust
SplunkTrust

This works for me:

eval time = strptime("2013-03-27T21:00:32.950000000Z", "%Y-%m-%dT%H:%M:%S.%9NZ")

...but only if I type the date in myself. If I copy your date string it fails because the dashes in your date string aren't dashes. Using your copied date string, I need to do this to make it work:

eval time = strptime(replace("2013‎-‎03‎-‎27T21:00:32.950000000Z", "\D", ""), "%Y%m%d%H%M%S%9N")

Aether
Engager

This solution doesn't appear to account for timezone, which Splunk automatically adjusts for. By adding a % before the Z, Splunk will not perform this adjustment, which unless you have your timezone set as GMT you dont want (this assumes its ACTUALLY zulu time).

Assuming you dont need to do the hyphen replacement, you can also shorthand the format to "%FT%T.%5N%Z"

The solution thus becomes:
eval time = strptime("2013-03-27T21:00:32.950000000Z", "%FT%T.%5N%Z")

or
eval time = strptime("2013-03-27T21:00:32.950000000Z", "%Y-%m-%dT%H:%M:%S.%9N%Z")

martin_mueller
SplunkTrust
SplunkTrust

I've copied your string into my Notepad++ and it comes out as ?-? for the dashes when trying to interpret them as ANSI, gibberish when trying to interpret them as UTF-8

0 Karma

landzaat
Explorer

Thanks. Never thought strings could be not what they look like. Valuable hint for all coming troubleshoots.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...