I know that '@' rounds off to the nearest time. For example, if we have 9:37, shouldn't it round off to 10 instead of 9?
@palisetty again I will recommend you to read about Time Modifiers and snap to time in the Splunk Documentation: https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SearchTimeModifiers#Specify_a_sn...
One of the easiest place to try out an learn about (1) Time Modifiers (2) snap to time and (3) offset is the Advance
dialog option within the Time Range Picker provided in the Splunk UI.
For example if current date is 01/02/2020
, then -1d@d
resolves to 01/01/2020 12:00:00.000 AM
. You can always split this and read as minus one day
( i.e. for -1d
) and snap-to the beginning of the day
(i.e. for @d
).
To further add the concept of offset, you can make the next level of adjustment by adding/subtracting offset to this time.
For example -0d@d-1s
or simply @d-1s
will snap to the beginning of the day yesterday but also subtract 1 second ensuring instead of 12:00 AM for today it will be 11:59:59 for yesterday
i.e. 01/01/2020 11:59:59.000
where as -0d@d
is 01/02/2019 12:00:00.000
.
Hope the above makes sense. Do try out the time modifiers in the Time Range input in Splunk to understand and practice the concept.
You can also try out the following run anywhere example where you need to add the Time Modifier to using relative_time() evaluation function to generate EPOCH time which is converted to string time of format YYYY-MM-DD HH:MM:SS
using fieldformat command.
| makeresults
| fields - _time
| eval Time=relative_time(now(),"-1d@d")
| fieldformat Time=strftime(Time,"%Y/%m/%d %H:%M:%S")
If today is 01/02/2020
then following is the output of "-1d@d" in relative_time()
function:
Time
2020/01/01 00:00:00
@palisetty again I will recommend you to read about Time Modifiers and snap to time in the Splunk Documentation: https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/SearchTimeModifiers#Specify_a_sn...
One of the easiest place to try out an learn about (1) Time Modifiers (2) snap to time and (3) offset is the Advance
dialog option within the Time Range Picker provided in the Splunk UI.
For example if current date is 01/02/2020
, then -1d@d
resolves to 01/01/2020 12:00:00.000 AM
. You can always split this and read as minus one day
( i.e. for -1d
) and snap-to the beginning of the day
(i.e. for @d
).
To further add the concept of offset, you can make the next level of adjustment by adding/subtracting offset to this time.
For example -0d@d-1s
or simply @d-1s
will snap to the beginning of the day yesterday but also subtract 1 second ensuring instead of 12:00 AM for today it will be 11:59:59 for yesterday
i.e. 01/01/2020 11:59:59.000
where as -0d@d
is 01/02/2019 12:00:00.000
.
Hope the above makes sense. Do try out the time modifiers in the Time Range input in Splunk to understand and practice the concept.
You can also try out the following run anywhere example where you need to add the Time Modifier to using relative_time() evaluation function to generate EPOCH time which is converted to string time of format YYYY-MM-DD HH:MM:SS
using fieldformat command.
| makeresults
| fields - _time
| eval Time=relative_time(now(),"-1d@d")
| fieldformat Time=strftime(Time,"%Y/%m/%d %H:%M:%S")
If today is 01/02/2020
then following is the output of "-1d@d" in relative_time()
function:
Time
2020/01/01 00:00:00
have a look here, splunk has round, ceil, floor functions that you can use along with eval command to perform rounding.
eg: ...| eval n=ceil(1.9)
returns n=2
@soumyasaha25 I think you missed the question, query was for snapping the time modifier. What you have provided is evaluation ceiling() function for numeric fields not Splunk Time format.
Thank You @soumyasaha25 I am not up to your level, I am just preparing for Fundamental 1 exam.
Hi @palisetty,
@ seems that you around the time period to the unit you add after @:
in other words, -h@h seems the full hout from 00 minute to 59 minute, -h@m arount to the full minute, so at 9.37 seems from 8.37.00.
In your example if you want to take logs at 9.37 from 8.00 to 9.00 you can use earliest=-h@h latest=@h
.
At 9.37 you cannot round to 10.00 because it's a future time.
Ciao.
Giuseppe
@gcusello we will go step by step, please be patient with me.
-h@h means? is it a previous hour?
for example, my current time is 4:56 what would -h@h constitute to?
a week ago @vnravikumar helped me understand -d@d means yesterday, -100d@d is like previous 100 days from today.
I am still stuck with time though.
Hi @palisetty,
No problem, ask what you need and take your times!
So -h@h
is the past hour (from 0 to 59 minutes), @h
is the start of the present hour.
In your example if you want to take logs at 9.37 from 8.00 to 8.59 you can use earliest=-h@h latest=@h
.
Ciao.
Giuseppe
@gcusello for snapping to 8:59
the correct time modifier will have snap-to as well as offset i.e.
@h-1s
which snaps to 08:59:59
, just @h
will snap to 09:00:00
Hi @palisetty,
As I said at 9.37 from 8.00 to 8.59 you can use earliest=-h@h latest=@h
, because you use -h@h
and @h
for earliest and latest so you can fix the time period in this way, you don't need to use @h-1s
for latest.
Ciao.
Giuseppe
@gcusello So, you are saying, for the example of 9:37, if I say -h@h. @h will be 9 and -h will be from 8:00 to 8:59.
Hi @palisetty,
As I said: -h@h is the past hour (at 9.39 it means 8.00), @h is the start of the present hour (at 9.39 it means 9.00).
Ciao.
Giuseppe
Perfect. Thank you. @gcusello you are one of the best mentors