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!

Exciting News: The AppDynamics Community Joins Splunk!

Hello Splunkers,   I’d like to introduce myself—I’m Ryan, the former AppDynamics Community Manager, and I’m ...

The All New Performance Insights for Splunk

Splunk gives you amazing tools to analyze system data and make business-critical decisions, react to issues, ...

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...