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!

Splunk APM & RUM | Upcoming Planned Maintenance

There will be planned maintenance of the streaming infrastructure for Splunk APM and Splunk RUM in the coming ...

Part 2: Diving Deeper With AIOps

Getting the Most Out of Event Correlation and Alert Storm Detection in Splunk IT Service Intelligence   Watch ...

User Groups | Upcoming Events!

If by chance you weren't already aware, the Splunk Community is host to numerous User Groups, organized ...