Splunk Search

How do I refine this search to use 'my_report_date' instead of _time?

mistydennis
Communicator

Hi all - I'm attempting to write a query using earliest/latest based off a date field in the event, not _time. I've tried a dozen things, and no matter what I try the earliest/latest fields are not showing what I expect.

I'm using 'my_report_date' as the desired earliest/latest field. When I run the following search, the earliest should be 11/1/22, but it shows as 11/2 (these events were sent to a summary index prior to the events of 11/1). The rest of the query is finding the number of days between first/last events.

How do I refine this search to use 'my_report_date' instead of _time?

 

index=summary 
| stats earliest(my_report_date) AS FirstFound, latest(my_report_date) AS LastFound by my_asset
| convert mktime(FirstFound) AS FirstFoundEpoch timeformat="%Y-%m-%d"
| convert mktime(LastFound) AS LastFoundEpoch timeformat="%Y-%m-%d"
| eval daysdiff=round((LastFoundEpoch-FirstFoundEpoch)/86400,0)
| stats count by my_asset, FirstFound, LastFound, daysdiff

 

 

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

The earliest/latest stats commands always base early/late on the event time. What you want is simply min/max of my_report_date, which must be an epoch, so you will need to convert it first, i.e.

| eval my_report_date=strptime(my_report_date, "%F")
| stats min(my_report_date) AS FirstFound, max(my_report_date) AS LastFound by my_asset

%F is shorthand for %Y-%m-%d

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

The earliest/latest stats commands always base early/late on the event time. What you want is simply min/max of my_report_date, which must be an epoch, so you will need to convert it first, i.e.

| eval my_report_date=strptime(my_report_date, "%F")
| stats min(my_report_date) AS FirstFound, max(my_report_date) AS LastFound by my_asset

%F is shorthand for %Y-%m-%d

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...