Splunk Search

remove timepart and convert to date so that i can aggregate at the date level

Raj_Splunk_Ing
Path Finder

Hi ,  I have this scenario where i am getting data from one of the index with 2 other specified filters like

index=index_logs_App989

customer="*ABC*"

org in ("Provider1","Provider2")

i have one filed with the date values as below

Tue 27 May 2025 15:26:23:702 EDT  - from this i have to take out the time part and convert it into date like 05/27/2025  - so that i can use this to aggregate at the date or day only ... any guidance please

 

 

 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

You can use the strptime and strftime functions to do that.

| eval date=strftime(strptime(<<someField>>, "%a %d %b %Y %H:%M:%S:%3N %Z"), "%m/%d/%Y")

where <<someField>> is the name of the field containing the date value shown.

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

You can use the strptime and strftime functions to do that.

| eval date=strftime(strptime(<<someField>>, "%a %d %b %Y %H:%M:%S:%3N %Z"), "%m/%d/%Y")

where <<someField>> is the name of the field containing the date value shown.

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

Raj_Splunk_Ing
Path Finder

Thank you Rick, exactly what i was looking for..  can i give you another scenario - just guide please

i have a field in the same index i dont have to show it in the table but i have to use a case statement to sum or count the number of transactions

status_code this will have values like 200, 201, 300, 302, 400,401, 500,502

i only need the count of events for  all 200  all 400 all 500 only  (dont need the one for 300)

trying to get this into case statement

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I'd use a separate field that contains the status codes of interest.  Something like this

| eval status=case(status_code<300 OR status_code>=400, status_code) ``` Other values of status_code set status to null```
| stats count by status
---
If this reply helps you, Karma would be appreciated.
0 Karma

Raj_Splunk_Ing
Path Finder

Hi Rich, since i am breaking them into separate columns - i used this using if condition

| eval TwoXXonly=if(status_code>=200 and status_code <300,1,0)
| eval FourXXonly=if(status_code>=400 and status_code <500,1,0)
| eval FiveXXonly=if(status_code>=500 and status_code <600,1,0)
| stats sum(TwoXXonly) as Total_2xx, sum(FourXXonly) as Total_4xx,sum(FiveXXonly) as Total_5xx

by date_only, org,cId,pPath, apie,apiPct,envnt

| table list of fieds

say for ex; in my data today i dont have 300 events but if they show up tomorrow - do i need to explicitly filter them out as i dont need them at all  - i have not used the status_code in by clause

just confused - should i use the filter to explicitly exclude 300 ?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

That's a great solution.

If you know you don't need/want events with status_code=3xx then you can (but don't have to) filter them out in the base query.  Filtering out events and fields you know you don't need will help the search perform better.

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...