Splunk Search

how to set earliest and latest for custom time

k_harini
Communicator

I have to set earliest to @d for the custom time stamp

query.. | dedup EMPLOYEE_ID |fields EMPLOYEE_ID STORE_NUMBER STATE REGION PUNCH_OUT_TIME|where PUNCH_OUT_TIME!= " "|eval punch_time= strptime(PUNCH_OUT_TIME,"%d/%m/%Y %H")|bin punch_time span=1h|stats count by REGION punch_time|eval punch_time = strftime(punch_time,"%d/%m/%Y %H %p")|xyseries punch_time REGION count|addtotals|eventstats avg(Total) as Average|rename Total as "Total Punched"|rename Average as "Average Punched"| rename punch_time as PUNCH_OUT_TIME

This query shows hour wise details for all dates. but I need only for current date.. I could not set earliest and latest here. How to do that? please help

Tags (1)
0 Karma
1 Solution

somesoni2
Revered Legend

If your _time value (timestamp extraction setup during indexing) is based on PUNCH_OUT_TIME field already, you could just include earliest=@d in your base query.

index=foo sourcetype=bar earliest=@d ....rest of the search...

If it's not based on PUNCH_OUT_TIME field, then try like this (see where condition)

query.. | dedup EMPLOYEE_ID |fields EMPLOYEE_ID STORE_NUMBER STATE REGION PUNCH_OUT_TIME|where PUNCH_OUT_TIME!= " "|eval punch_time= strptime(PUNCH_OUT_TIME,"%d/%m/%Y %H") 
| where punch_time>=relative_time(now,"@d")
...rest of the search...

View solution in original post

0 Karma

k_harini
Communicator

This is what worked. Thanks somesoni2 :).. you are very helpful

0 Karma

somesoni2
Revered Legend

If your _time value (timestamp extraction setup during indexing) is based on PUNCH_OUT_TIME field already, you could just include earliest=@d in your base query.

index=foo sourcetype=bar earliest=@d ....rest of the search...

If it's not based on PUNCH_OUT_TIME field, then try like this (see where condition)

query.. | dedup EMPLOYEE_ID |fields EMPLOYEE_ID STORE_NUMBER STATE REGION PUNCH_OUT_TIME|where PUNCH_OUT_TIME!= " "|eval punch_time= strptime(PUNCH_OUT_TIME,"%d/%m/%Y %H") 
| where punch_time>=relative_time(now,"@d")
...rest of the 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 ...