Splunk Search

Why is strptime and strftime command not working as expected?

monyathomas
New Member

I have two "Survey Type" - 'a' and 'b' and I need to display their count based on the"Survey Complete" data.
Note - The Survey Complete date is in the format MM/DD/YYYY HH:MM format but I need to display it as MM-YYYY format . How do I reframe the below query to get the expected output mentioned above.

index="xyz"
| eval FIELD=strptime("Survey Complete","%m/%d/%Y %H:%M")
| eval DesiredTime=strftime(FIELD,"%Y-%m-%d")
| chart count over "Survey Complete" by "Survey Type"

Tags (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

You don't say what unexpected output you get, but your query doesn't match your question so that could be it.

Try this:

index="xyz" 
| eval FIELD=strptime("Survey Complete","%m/%d/%Y %H:%M") 
| eval DesiredTime=strftime(FIELD,"%m-%Y")
| chart count over "Survey Complete" by "Survey Type"

You can also use a single eval:

index="xyz" 
| eval DesiredTime=strftime(strptime("Survey Complete","%m/%d/%Y %H:%M"), "%m-%Y)
| chart count over "Survey Complete" by "Survey Type"
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...