Getting Data In

Convert date string to timestamp

Master162
New Member

Hi,

I have a field called datetime - example is datetime=Wed Feb 03 17:56:37 UTC 2021

I essentially want to convert this so I can evaluate the difference between the event timestamp with this datetime field. I have already converted the event timestamp using: | eval input=strptime(_time, "%m/%d/%Y %I:%M %p") ---> this would show me 2021-02-03 18:07:42.958

How do I convert the datetime field so it's in the same format and how to show the difference between these fields?

Labels (1)
0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @Master162,

Please try this;

| eval datetime_epoc=strptime(datetime,"%a %b %d %H:%M:%S %Z %Y") 
| eval diff=_time-datetime_epoc
If this reply helps you an upvote and "Accept as Solution" is appreciated.
0 Karma
Get Updates on the Splunk Community!

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...