Splunk Search

Is it possible to round the current time in a quarter of hour ( quarter superior)?

jip31
Motivator

Hi

Is it possible to round the current time in a quarter of hour ( quarter superior)

For exemple if its 9h56 i would like to diplay 10:00 and 11:42 i would like to display 11:45

Thanks

Tags (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

fieldformat doesn't change the value of the field, it just changes the way the field is display. Change it to

| eval current=strftime(current,"%H:%M")

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval _time=_time+(15*30)-1
| bin _time span=15m
| fieldformat _time=strftime(_time,"%H:%M")

jip31
Motivator

it works fine but i need to do the same thing from the currnt time...

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval current=now()+(15*30)-1
| bin current span=15m
| fieldformat current=strftime(current,"%H:%M")
0 Karma

jip31
Motivator

it seems to be what I need

but when I compare the current time with the past time (see my where clause) it displays nothing

`index` sourcetype="session"  earliest=-7d@d+7h latest=-7d@d+19h 
| bin _time span=15m 
| eval time=strftime(_time,"%H:%M") 
| stats dc(s) as s by time 
| eval current=now()+(15*30)-1 
| bin current span=15m 
| fieldformat current=strftime(current,"%H:%M") 
| where time=current
| table s time current

 it's strange because I can see data on the same slot time

jip31_0-1651303312101.png

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

fieldformat doesn't change the value of the field, it just changes the way the field is display. Change it to

| eval current=strftime(current,"%H:%M")
0 Karma

jip31
Motivator

perfect ITWhisperer, thanks

0 Karma

DanielPriceUK
Path Finder

Remainder=Time % 900
Time=Time-Remainder
If Reminder >=450 then Time=Time+900

You can do each step here with the splunk Eval command.

Time needs to be in Unix: here the docs to help with that https://docs.splunk.com/Documentation/SCS/current/SearchReference/DateandTimeFunctions

0 Karma

jip31
Motivator

Hi

So if i well understand i cant have a date in H:M: format?

0 Karma

DanielPriceUK
Path Finder

you can use  the functions, strftime and strptime to change between formats.
you can read about them here.
https://docs.splunk.com/Documentation/SCS/current/SearchReference/DateandTimeFunctions

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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...