Splunk Search

How to get the 6 month ago column from field in lookup?

urapaveerapan
Explorer

Hi,

I have a column named Month in lookup file

For example,
Month
2017/02
2017/01
2017/01
2017/01
2016/12
2016/12

I need to get the maximun month and the month in 6 month ago
ex. Maximum month = 2017/04, 6 month ago=2016/10

I tried strftime, strptime, relative_time but it's not working.
Please help.alt text

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi
you have to transform your month in epochtime and then find max and calculate six months later, try something like this:

| inputlookup your_lookup 
| eval Month=Month+"/01" 
| eval date_month1=strptime(Month,"%Y/%m/%d")
| stats max(date_month) AS max_month
| eval Max_Month=strftime(max_month,"%Y/%m")
| eval Month_6_later=relative_time(Max_Month,"+6mon"), Date_Month_6_later=strftime(Month_6_later,"%Y/%m")
| table Max_Month Date_Month_6_later

Bye.
Giuseppe

0 Karma

urapaveerapan
Explorer

| inputlookup pcm_incoming_ticket_lookup
| eval Month=Month+"/01"
| eval date_month1=strptime(Month,"%Y/%m/%d")
|table Month, data_month1

No data shown in data_month1 column but Month work fine.

0 Karma

gcusello
SplunkTrust
SplunkTrust

beware that in eval you have "date_month1", instead in table you have "data_month1", they are different ("data" instead "date").
Bye.
Giuseppe

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!

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

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