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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...