Splunk Search

strftime day and month: Splunk vs Python

pm771
Communicator

My question is about day and month components of a date without leading zeroes.

Python docs provide %-d and %-m respectively.

Splunk docs do not show these options.  Splunk, however, has %e which seems to be the same as %-d.  I did not find any option for decimal month number.

I have tried and Splunk seems to accept %-d and %-m

Is it standard feature that I can rely on? Is it implementation dependent?

Did I miss something in Splunk docs?

Labels (1)
Tags (2)
0 Karma

yeahnah
Motivator

Hi @pm771 

I think the Splunk docs are not very detailed about this and could be improved, for sure.  I believe it's just python libraries in the Splunk backend so, yes, any valid python strftime() modifiers will work (dependent on the installed Splunk python version).

Here's a run anywhere example I tried.

 

| makeresults
| eval epoch=relative_time(_time, "@month")
      ,date1=strftime(relative_time(epoch, "@month"), "%Y-%m-%d")
      ,date2=strftime(relative_time(epoch, "@month"), "%Y-%m-%e")
      ,date3=strftime(relative_time(epoch, "@month"), "%Y-%-m-%-d")
      ,date4=strftime(relative_time(epoch, "@month"), "%Y-%#m-%#d")

 


Note the %e has a leading whitespace so stick to either %-d or %#d.

Hope this helps.

 

Get Updates on the Splunk Community!

Splunk Edge Processor | Popular Use Cases to Get Started with Edge Processor

Splunk Edge Processor offers more efficient, flexible data transformation – helping you reduce noise, control ...

3 Ways to Make OpenTelemetry Even Better

My role as an Observability Specialist at Splunk provides me with the opportunity to work with customers of ...

What's New in Splunk Cloud Platform 9.2.2406?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2406 with many ...