Splunk Search

strptime and mktime not generating any values

thyrfa
New Member

I have a CSV with a date field that I want to convert to a timefield so that I can timechart it. When I run

 ...| rename "field I want" as time | eval time = case(substr(time, 1, 2) LIKE "%/", "0"+time, 1=1, time) |  convert timeformat="%m/%e/%Y  %I:%M %p" mktime(time) |

time ends up being always null. When I do

...| rename "field I want" as time | eval time = case(substr(time, 1, 2) LIKE "%/", "0"+time, 1=1, time) | eval ntime=strptime(time, "%m/%e/%Y  %I:%M %p") |

ntime doesn't even get created as a field. I'm 100% sure that the formatting is correct (though theres always a chance for errors) and I've tried everything I can think of. Why does neither function evaluate? An example of one of the strings I'm trying to convert is "1/1/2013 12:00 AM".

0 Karma
1 Solution

somesoni2
Revered Legend

I don't think you need that case statement at all. Following direct conversion works (run anywhere sample)

| gentimes start=-1 | eval time="1/1/2013 12:00 AM" | table time| eval ntime=strptime(time,"%m/%d/%Y %H:%M %p")

View solution in original post

0 Karma

somesoni2
Revered Legend

I don't think you need that case statement at all. Following direct conversion works (run anywhere sample)

| gentimes start=-1 | eval time="1/1/2013 12:00 AM" | table time| eval ntime=strptime(time,"%m/%d/%Y %H:%M %p")
0 Karma

thyrfa
New Member

Woah that worked! The issue was me putting the table after evaluating ntime. Why does that matter?

0 Karma

somesoni2
Revered Legend

It won't. Probably the timeformat you used was the issue, along with additional formatting you were trying.

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...