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
Explorer

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
Explorer

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
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...