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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...