Splunk Search

Formatting String to Time returns nothing

aelliott
Motivator

Here is my query:
"TSStart"="2013-10-14T18:35:03.487" | eval MyTime=strptime(TSStart,"%Y-%m-%dT%T")

My Time Format for start time is in the format as above: 2013-10-14T18:35:03.487
The goal of this is to show the datetime in a format that is more readable, I want to first attempt to parse it into a timestamp format.
This is not the same field I am using for my Timestamp value as there is also a TSEnd within the data that I will need to format.

My query is not coming back with anything for "MyTime" and not throwing any errors in the logs.
Is my date format string incorrect? I have tried several variations and cannot get this to work.

Tags (2)
0 Karma
1 Solution

aelliott
Motivator

Ok I believe I have figured out this issue. I am using an XML type of Structure and the fields are auto mapped via the KV_MODE = xml. The Field is Actually Event.TSStart.
I did a rename on the field (| rename Event.TSStart as TSStart) and it started working.

I attempted first to surround Event.TSStart with Quotations, but it litterally put "Event.TSStart" in the formula.

I am not sure if this is a bug or intended.

View solution in original post

aelliott
Motivator

Ok I believe I have figured out this issue. I am using an XML type of Structure and the fields are auto mapped via the KV_MODE = xml. The Field is Actually Event.TSStart.
I did a rename on the field (| rename Event.TSStart as TSStart) and it started working.

I attempted first to surround Event.TSStart with Quotations, but it litterally put "Event.TSStart" in the formula.

I am not sure if this is a bug or intended.

aelliott
Motivator

Basically if your field has a . in it, the formulas fail, even trim

somesoni2
Revered Legend

I tried your search and its working for me. I see you want to get rid of milliseconds (otherwise the format is same). Can you try following: "TSStart"="2013-10-14T18:35:03.487" | eval MyTime=strptime(mvindex(split(TSStart,"."),0),"%Y-%m-%dT%T")

0 Karma

richgalloway
SplunkTrust
SplunkTrust

That works for me.

| eval TSStart="2013-10-14T18:35:03.487" | eval MyTime=strptime(TSStart,"%Y-%m-%dT%T") | eval MyTime2=strptime(TSStart,"%Y-%m-%dT%H:%M:%S.%3N") | table TSStart, MyTime, MyTime2

TSStart MyTime MyTime2
2013-10-14T18:35:03.487 1381790103.000000 1381790103.487000

---
If this reply helps you, Karma would be appreciated.
0 Karma

aelliott
Motivator

Yeah I've tried
strptime(TSStart,"%Y-%m-%dT%T.%3N") and seperating hour, minute, second as well.
I just tried the one you have there and it did not work either

0 Karma

lukejadamec
Super Champion

Have you tried including the milliseconds?
"TSStart"="2013-10-14T18:35:03.487" | eval MyTime=strptime(TSStart,"%Y-%m-%dT%T.%f")

0 Karma
Get Updates on the Splunk Community!

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...

Purpose in Action: How Splunk Is Helping Power an Inclusive Future for All

At Cisco, purpose isn’t a tagline—it’s a commitment. Cisco’s FY25 Purpose Report outlines how the company is ...

[Upcoming Webinar] Demo Day: Transforming IT Operations with Splunk

Join us for a live Demo Day at the Cisco Store on January 21st 10:00am - 11:00am PST In the fast-paced world ...