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!

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 ...