Splunk Enterprise

compare 6 months ago to start date(can be any specific date)

rivkah01
Observer
we need to check which courses were started during the month of last half a year.

the code I wrote for it:

 "start date" - format : 2021-03-22 f

"last_6_months".  - calculated now()-6 month

below the query we tried but its not working

could you please advise? 

 

`ssdlc_base("all time back")`
| where email_address!="NA"
| lookup ssdlc_bu_courses.csv BU output courses
| mvexpand courses
| lookup ssdlc_bu_courses.csv BU courses output "start date"
| rename "start date" as "start_date1"
| mvexpand "start_date1"
| eval start_date=strptime(strftime(start_date1,"%Y-%m-%d")."-01","%Y-%m-%d")
| eval last_6_months=strptime(strftime(relative_time(now(),"-6mon"),"%Y-%m")."-01","%Y-%m-%d")
| fields start_date ,last_6_months , start_date1

Labels (1)
0 Karma

Micheal_S
Path Finder

Playing around with some results it doesn't seem to affect anything, but I was also concerned about the ."-01" in this line from your original post, the resulting output of the strftime() function wouldn't fit the format.  You'd end up with something like 2021-03-22-01.

| eval start_date=strptime(strftime(start_date1,"%Y-%m-%d")."-01","%Y-%m-%d")

 

0 Karma

Micheal_S
Path Finder

I had a couple questions in your start date format, what does the "f" at the end of the date format mean? 

2021-06-21 10_11_35-Reply to Message - Splunk Community.png

Can you provide a sample value of "start_date1" from just after mvexpand "start_date1" but before you perform any evals on it? 

2021-06-21 10_11_58-Reply to Message - Splunk Community.png

0 Karma

rivkah01
Observer

not working the dates are not in the same format.

rivkah01_0-1624190537377.png

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval start_date=relative_time(strptime(start_date1,"%Y-%m-%d"),"@mon")
| eval last_6_months=relative_time(now(),"-6mon@mon")
0 Karma

rivkah01
Observer

still no change:

rivkah01_0-1624191072166.png

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

The field you are showing is "start date" not start_date. What is is start_date and start_date1?

 

0 Karma

rivkah01
Observer

rivkah01_0-1624280950116.png

no data for start_date

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

That's because you removed the rename you had previously. Either put it back in or use

| eval start_date=relative_time(strptime('start date',"%Y-%m-%d"),"@mon")
| eval last_6_months=relative_time(now(),"-6mon@mon")
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try changing these two lines

| eval start_date=relative_time(start_date1,"@mon")
| eval last_6_months=relative_time(now(),"-6mon@mon")
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...