Splunk Search

Add time in search string

vik123ash
Explorer

Hi All,

i want to add time in search string.

My data is showing time 26-02-2018T02:00:00.000+0000, but while searching i want to add 11 hour , means it should create filter for time 27-02-2018T13:00:00.000+0000.

Also after this i also want to apply substring on time to just show dates.

i am using below one, but its not working.

index=XXXXXX source="XXXXXX" |eval host=add(Date,+11) | eval hostgroup=substr(Date,1,10) | stats count(Date) by hostgroup

Please help.

Vikash

Tags (1)
0 Karma

p_gurav
Champion

Try this:

index=XXXXXX source="XXXXXX" |eval date=strptime(CDate, "%d-%m-%Y %H:%M:%S.%3N%z") | eval date1=date+39600 | eval hostgroup =strftime(date1, "%d-%m-%Y") | stats count(CDate) by hostgroup

0 Karma

p_gurav
Champion

Hi,

This may be helpful for you:

index=XXXXXX source="XXXXXX" |eval date=strftime(Date, "%d-%m-%Y %H:%M:%S.%3N%z") | eval date1=date+39600 | eval  hostgroup =strptime(date1, "%d-%m-%Y") | stats count(date) by hostgroup
0 Karma

vik123ash
Explorer

@p_gaurav

Thanks for your quick reply.

Query is not provding any output.

0 Karma

p_gurav
Champion

Hi,

can you tell me output of this:
index=XXXXXX source="XXXXXX" |eval date=strftime(_time, "%d-%m-%Y %H:%M:%S")

0 Karma

vik123ash
Explorer

I have too many date fields, out of which i want to create filter for one of the date field. i am not sure if _time will help here.

Below is the date field on which i need to execute the query.
CDate: 2018-02-27T03:55:28.000+0000

0 Karma

vik123ash
Explorer

Hi @p_gaurav

We are getting output 0 though we have non-zero value.

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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