Dashboards & Visualizations

How to convert dateTime and calculate difference?

AzmathShaik
Path Finder

i have a field as createddate where the DateTime format is as below
2023-02-28T21:55:35.646-08:00
2022-03-24T02:42:16.983-07:00
i'm trying to calculate the difference between now and createddate. can some help me in doing so. i tried to convert createddate and get the difference but no luck

Thanks in advance

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this set of SPL commands

| eval time=strptime(createddate,"%Y-%m-%dT%H:%M:%S.%3N%:z")
| eval diff=now()-time
---
If this reply helps you, Karma would be appreciated.
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval _time=strptime(createddate,"%FT%T.%3N%:z")
| eval diff=now()-_time

AzmathShaik
Path Finder

unfortunately it is not extracting the values

0 Karma

bowesmana
SplunkTrust
SplunkTrust

That syntax is correct - here's an example using your data and ITWhisperer's solution

| makeresults 
| fields - _time 
| eval createddate=split("2023-02-28T21:55:35.646-08:00,2022-03-24T02:42:16.983-07:00", ",")
| mvexpand createddate
``` Suggested solution ```
| eval _time=strptime(createddate,"%FT%T.%3N%:z")
| eval diff=now()-_time

so if it's not extracting then either you don't have a field called createddate or it is not in the format you suggest.

Can you post your SPL and an screenshot of your data.

Get Updates on the Splunk Community!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...