Splunk Search

How to convert field date into week values?

ranjitbrhm1
Communicator

Good Day all, I have a query, I am uploading a CSV regularly onto splunk. Since its uploaded in a random time, splunk time does not apply here. The CSV actually have a field which has all the dates in them in DD-MM-YYYY format. My intention is to make a dashboard which is able to filter based on weeks 1-4 for events. Is there a method to determine what week the dates fall under i.e 4/01/2017 falls to week one, 10/4/2017 falls in week 2 etc? I know it might be a long shot, but is this a possibility?

0 Karma
1 Solution

FrankVl
Ultra Champion

First convert the date field to a timestamp, by parsing it using strptime, then translate that into a string containing the weeknumber using strftime. There are multiple different weeknumber standards, so replace %V with the correct one for your needs (see http://php.net/manual/en/function.strftime.php for details).

| eval weeknum=strftime(strptime(yourdatefield,"%d-%m-%Y"),"%V")

View solution in original post

FrankVl
Ultra Champion

First convert the date field to a timestamp, by parsing it using strptime, then translate that into a string containing the weeknumber using strftime. There are multiple different weeknumber standards, so replace %V with the correct one for your needs (see http://php.net/manual/en/function.strftime.php for details).

| eval weeknum=strftime(strptime(yourdatefield,"%d-%m-%Y"),"%V")

ranjitbrhm1
Communicator

175% correct answer. Thanks for the link as well.

0 Karma
Get Updates on the Splunk Community!

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...