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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...