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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

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