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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...