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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...