Splunk Search

How do I extract a year and use as a chart?

devfrag
New Member

I have a csv lookup that has the date in MM/DD/YYYY format. I managed to get the data into splunk with DBConnect. Ultimately I will be creating a ITSI dashboard panel with a bar chart comparing this year to last. What is the best way to accomplish this?

Date Completed Users
1/15/2018 6113 3762
1/16/2018 2505 1714
1/13/2017 7029 4410
1/14/2017 8797 5510
1/15/2017 10165 6187
1/16/2017 11948 6569
1/17/2017 10106 5236

Tags (3)
0 Karma

nrduren1115
Explorer

You can use the strptime and strftime methods to convert them from unix timestamps back into readable dates. Using your example you could use:

| eval timestamp = strptime(Date,"%m/%d/%Y"), Year = strftime(timestamp,"%Y")

The first command takes the Date object and turns it into a 10 digit timestamp of seconds. The second command takes that time and returns the value from that timestamp you want, in this case year. The full list of time variables can be found here:

https://docs.splunk.com/Documentation/Splunk/7.2.0/SearchReference/Commontimeformatvariables

The next step you can use to do stats grouped by Year:

| stats count, avg(Field1), max(Field2) by Year
0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

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