Splunk Search

Why is strptime not returning results for a date field in my data?

ErikaE
Communicator

I have a time in the following format: 2015-08-11 16:31:25.973 in a field called "Last Modified On". The data comes from a log with several columns containing date time information.

What I'd like is to get a field at search-time that has just the date from the "Last Modified On" field, so I can group other fields by that date at search-time.

Here is my search:

host=* | eval test=strptime('Last Modified On',"%Y%m%d") | table test "Last Modified On"

The output is a table with blanks for all the test field values, and the date time in the Last Modified On field.

I have read other questions, but can't seem to find a similar example where strptime returns a blank for a string date. Is there a way to confirm that "Last Modified On" contains string data?

Tags (4)
0 Karma
1 Solution

maciep
Champion

I think you need to put the dashes in your format string, since they're in your last modified on field

eval test=strptime('Last Modified On',"%Y-%m-%d")

View solution in original post

maciep
Champion

I think you need to put the dashes in your format string, since they're in your last modified on field

eval test=strptime('Last Modified On',"%Y-%m-%d")

ErikaE
Communicator

Awesome. The answer was in epoch time but I was able to convert it with strftime.

LastModDate=strftime(strptime('Last Modified On',"%Y-%m-%d"),"%m %d %Y")
Get Updates on the Splunk Community!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

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 ...