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

Labels (1)
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
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...