Splunk Search

How to convert a number into a Date?

mattheuslima
Explorer

Hello, Folks. 

I have a field that represents a date but in this format (YY/MM/DD).

For example:  on 07/23/20 the field value will be 200723. 

I need to transform this value into a date (DD/MM/YY). 

I tried to use:

| eval MyDateEpoch=strptime(MyDate,"%Y%m%d")

but doesn't work. 

Can you help me ?

Labels (1)
Tags (1)
0 Karma
1 Solution

to4kawa
Ultra Champion
| makeresults
| eval MyDate="200723"
| rex field=MyDate mode=sed "s/(\d\d)(\d\d)(\d\d)/\3\/\2\/\1/"

If MyDate is text, rex is useful.

View solution in original post

to4kawa
Ultra Champion
| makeresults
| eval MyDate="200723"
| rex field=MyDate mode=sed "s/(\d\d)(\d\d)(\d\d)/\3\/\2\/\1/"

If MyDate is text, rex is useful.

mattheuslima
Explorer

It work!!

Thank you !!!!

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

you should try “%y%m%d” as format string. %y is 99 and %Y is 9999.

r. Ismo

0 Karma

mattheuslima
Explorer

Hi, @isoutamo . Thanks for answer!

Unfortunately it doesn't work. 

I got this as an answer   "Error in 'eval' command: The expression is malformed. Expected AND."

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Please try this:

 

index=_audit
| head 1
| eval MyDate="200723"
| eval MyDateEpoch=strptime(MyDate,"%y%m%d")
| eval NewDate=strftime(MyDateEpoch, "%d/%m/%y")
| table MyDate MyDateEpoch NewDate

 

0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...