Splunk Search

Convert this time format to epoch

hagjos43
Contributor

I have a time in the format of:
3:21:34 AM 12/8/2014

I'm trying to convert this to epoch time. Can anyone lend a hand?

Thanks!

Tags (4)
1 Solution

somesoni2
Revered Legend

Try any of strptime or convert command.

e.g.

| gentimes start=-1 | eval YourDate="3:21:34 AM 12/8/2014" | table YourDate 
| eval epoch1=strptime(YourDate,"%H:%M:%S %p %m/%d/%Y") 
| convert timeformat="%H:%M:%S %p %m/%d/%Y" mktime(YourDate) as epoch2

View solution in original post

somesoni2
Revered Legend

Try any of strptime or convert command.

e.g.

| gentimes start=-1 | eval YourDate="3:21:34 AM 12/8/2014" | table YourDate 
| eval epoch1=strptime(YourDate,"%H:%M:%S %p %m/%d/%Y") 
| convert timeformat="%H:%M:%S %p %m/%d/%Y" mktime(YourDate) as epoch2

pratikkadam
New Member

Can you tell me what is the unit of the time which is converted to Epoch format?
@somesoni2

0 Karma

493669
Super Champion

It's in seconds

0 Karma

hagjos43
Contributor

Perfect, thank you very much!

0 Karma

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

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

0 Karma

to4kawa
Ultra Champion
| eval "Bridge End Date In Sec"=strptime('Bridge End Date',"%m/%d/%Y %H:%M:%S %p")
| eval "Bridge Start Date In Sec"=strptime('Bridge Start Date',"%m/%d/%Y %H:%M:%S %p")
0 Karma

nagarjuna280
Communicator

I got same results for both AM and PM

0 Karma

kml_uvce
Builder

try this

eval t="your time field"

kamal singh bisht
0 Karma

hagjos43
Contributor

Thanks, but that did not work 😞
Returns a result like this: 10:26:26 AM 12/2/2014

My query is:
sourcetype=WinEventLog:Security EventCode=520 | eval t=New_Time

0 Karma

kml_uvce
Builder

try this..
eval t=_time

t will be your new field

kamal singh bisht
0 Karma
Get Updates on the Splunk Community!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...