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?

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 Observability Cloud’s AI Assistant in Action Series: Analyzing and ...

This is the second post in our Splunk Observability Cloud’s AI Assistant in Action series, in which we look at ...

Elevate Your Organization with Splunk’s Next Platform Evolution

 Thursday, July 10, 2025  |  11AM PDT / 2PM EDT Whether you're managing complex deployments or looking to ...

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...