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"))
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...