Dashboards & Visualizations

Convert Time format

goyals05
Explorer

Hi,

I am getting time stamp as "2017-10-26T16:59:29.565+0200". How can I convert it in "2017-10-26 16:59:29" format.

Thanks

Tags (2)
1 Solution

niketn
Legend

@goyals05, I hope the above example is timestamp is String Time and not Epoch Time.
You can convert String Time in your old format to Epoch Time in new format using strptime() and then convert to string time of your new format using strftime()

In order to understand the conversion you can try the following run anywhere search:

|  makeresults
|  eval myTimeOld="2017-10-26T16:59:29.565+0200"
|  eval myTimeNewEpoch=strptime(myTimeOld,"%Y-%m-%dT%H:%M:%S")
|  eval myTimeNew=strftime(myTimeNewEpoch,"%Y-%m-%d %H:%M:%S")

You can cascade this conversion in a single eval like the following as well:

|  makeresults
|  eval myTimeOld="2017-10-26T16:59:29.565+0200"
|  eval myTimeNew=strftime(strptime(myTimeOld,"%Y-%m-%dT%H:%M:%S"),"%Y-%m-%d %H:%M:%S")

Please try out and confirm.

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

View solution in original post

niketn
Legend

@goyals05, I hope the above example is timestamp is String Time and not Epoch Time.
You can convert String Time in your old format to Epoch Time in new format using strptime() and then convert to string time of your new format using strftime()

In order to understand the conversion you can try the following run anywhere search:

|  makeresults
|  eval myTimeOld="2017-10-26T16:59:29.565+0200"
|  eval myTimeNewEpoch=strptime(myTimeOld,"%Y-%m-%dT%H:%M:%S")
|  eval myTimeNew=strftime(myTimeNewEpoch,"%Y-%m-%d %H:%M:%S")

You can cascade this conversion in a single eval like the following as well:

|  makeresults
|  eval myTimeOld="2017-10-26T16:59:29.565+0200"
|  eval myTimeNew=strftime(strptime(myTimeOld,"%Y-%m-%dT%H:%M:%S"),"%Y-%m-%d %H:%M:%S")

Please try out and confirm.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...