Splunk Search

Conversion from string to date

c_sahil
New Member

I am having a field deliveryExpiry (String type) in my log and I want to compare whether the expiry is before the current date or after.Below I am giving the sample log

deliveryExpiry=Wed Dec 25 18:30:00 GMT 2013 deliveryNumber=110 MESSAGE=delivered

i tried something like this

| eval expiryDate=strptime(deliveryExpiry,"%a %b %d %H:%M:%S %Z %Y") | eval current=now() | where expiryDate>strptime(current,"%a %b %d %H %M %S %Z %Y")

but No luck.can anyone please help

Tags (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The now() function returns an integer so there's no need to strptime() it. Using 'where expiryDate>current' should do the trick.

---
If this reply helps you, Karma would be appreciated.

richgalloway
SplunkTrust
SplunkTrust

Have you tried replacing 'where expiryDate=date' with 'table expiryDate,date' to see why they don't match?

---
If this reply helps you, Karma would be appreciated.
0 Karma

c_sahil
New Member

when i tried the below query then also it didn't work..

| eval expiryDate=strptime(deliveryExpiry,"%a %b %d %H:%M:%S %Z %Y") | eval date=strptime(deliveryExpiry,"%a %b %d %H:%M:%S %Z %Y") | where expiryDate=date

0 Karma

c_sahil
New Member

It didn't worked. is it because i am not converting the date properly in expiryDate??

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...