Splunk Search

COnversion of PM /AM time to epoch not working as expected

ashanka
Explorer

2/11/2020 11:49:00 AM 2/11/2020 9:55:00 PM

How to convert this into Secs.. Conersion of AM and PM is not working as expected

2/11/2020 9:55:00 PM

| eval "Bridge End Date In Sec"=tonumber(strftime(strptime('Bridge End Date',"%m/%d/%Y %H:%M:%S %p"),"%s"))

1581440100

2/11/2020 11:49:00 AM
| eval "Bridge Start Date In Sec"=tonumber(strftime(strptime('Bridge Start Date',"%m/%d/%Y %H:%M:%S %p"),"%s"))

1581446940

%p is not wrking?

1581440100 1581446940 Values retued as this which is not correct. End is lesser thatn the start date

0 Karma
1 Solution

harsmarvania57
Ultra Champion

Hi,

You need to use %I instead of %H, %H is for 24 hour format and in this case it will take 09 PM as 09 AM

So try

| eval "Bridge End Date In Sec"=tonumber(strftime(strptime('Bridge End Date',"%m/%d/%Y %I:%M:%S %p"),"%s"))

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

I get different numbers for the same date-time strings. Perhaps it's because you're over-working them (strptime returns a number so there's no need to convert back to a string and into a number again). Try

| eval "Bridge End Date In Sec"=strptime('Bridge End Date',"%m/%d/%Y %H:%M:%S %p")
---
If this reply helps you, Karma would be appreciated.
0 Karma

harsmarvania57
Ultra Champion

Hi,

You need to use %I instead of %H, %H is for 24 hour format and in this case it will take 09 PM as 09 AM

So try

| eval "Bridge End Date In Sec"=tonumber(strftime(strptime('Bridge End Date',"%m/%d/%Y %I:%M:%S %p"),"%s"))
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...