Splunk Enterprise

unable to convert string type date format to Date format.

satishachary199
New Member

My uploaded source having String type date format with different types like ('MAY-15' ,'May-2015','MAY-2015', 'May-15' ) want to covert all this to Date format like "MAY-2015" while searching for report.

Thanks in Adavance.

Tags (1)
0 Karma

niketn
Legend

@satishachary1991 are you uploading this as lookup or indexing in Splunk? Can you add few sample events?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

cpetterborg
SplunkTrust
SplunkTrust

In your specific case (as you describe the data above):

...| rex field=data mode=sed "s/([a-z]+)-20(\d+)/\\1-\\2/" 
| eval data=upper(data) 
| rex field=data mode=sed "s/-/-20/"

should give you a date like MAY-2015 in all these cases. It also assumes that the file data has MMM-YYYY or MMM-YY as the format.

0 Karma

satishachary199
New Member

yes the format is 'MMM-YY', thank you for solution, its working fine for 2015 only in my case not working with other year like 2016,2013,2014 , the result is coming ('APR-202012' , 'APR-202016', 'OCT-202013')
and still it's string type for that when applying "sort -data" its sorting alphabetically , can we able to make sort month wise and year wise by coverting date format?

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

The change that needs to be made to the above was to include both upper and lower case in the regular expression. Here is a run-anywhere example that works for what you want.

| makeresults
| eval data="('MAY-15' ,'May-2015','MAY-2015', 'May-15' , 'may-2014', 'MaY-2016')"
| rex field=data mode=sed "s/([A-Za-z]+)-20(\d+)/\\1-\\2/g" 
| eval data=upper(data) 
| rex field=data mode=sed "s/-/-20/g"
0 Karma

somesoni2
Revered Legend

Look at lower function available with eval to normalize the case of value of a field.

0 Karma

satishachary199
New Member

Hi somesoni , i tried with your answer , actually the probem i am facing with in my .csv file the filed represent MMM-YY format , when i am uploading in splunk and doing search i am not able to convert String type to date type. for that i am missing date functionality search. Could you help on this.

0 Karma
Get Updates on the Splunk Community!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...