Splunk Search

Why the function "strftime" not working in my search query?

chrismok
Path Finder

alt textIf I use this, no event return

sourcetype=abc source="*"+strftime(now(),"%Y%m%d")+"*"

But when I modify the query to

sourcetype=abc source="*20141104*"

There is a events return.

May I know is that a bug in Splunk?

Tags (1)
0 Karma
1 Solution

peter_krammer
Communicator

Here is what you are looking for

sourcetype=abc [|stats count | eval source = "*"+strftime(now(),"%Y%m%d")+"*" | fields source | format]

Edited Answer to show the better performance solution found by davebrooking, but optimized a little by me.

View solution in original post

peter_krammer
Communicator

I just tried out your solution and it works, if eval-based definition is checked.
So thank you.

MuS
Legend

you're welcome 😉

MuS
Legend

looking at this picture, it's absolutely clear why your first search is the fastest: using any fields like index or source in the base search will speed up the search. Using a sub search will basically double search times but also speeds up the base search because you can use source in it and mine example simply does not provide any source field in the base search.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...