Splunk Search

Time Conversion

mbasharat
Builder

Hi,

I have time format as:
2019-10-08 15:24:40.132 UTC

I used eval to strip it to:
2019-10-08 15:24:40

I need to calculate Age. My eval is below but it is not working. Can someone assist pls?

| eval age=ceiling((now()-strptime(Event_Created_Time_Date,"%F %H:%M:%S"))/86400)

| eval Event_Age=case(
age<1,"1_Less than 1 Days",
age>=30,"6_Older than 30 Days",
age>=20,"5_Older than 20 Days",
age>=10,"4_Older than 10 Days",
age>=5,"3_Older than 5 Days",
age>=2,"2_Older than 2 Days",
0==0,"7_No Age Data")

Labels (1)
Tags (1)
0 Karma
1 Solution

manjunathmeti
Champion

hi @mbasharat, For timezone (UTC) you can set variable "%Z".

Try this:

| makeresults 
| eval Event_Created_Time_Date="2019-10-08 15:24:40.132 UTC" 
| eval age=ceiling((now() - strptime(Event_Created_Time_Date, "%Y-%m-%d %H:%M:%S.%3N %Z"))/86400) 
| eval Event_Age=case(
    age<1,"1_Less than 1 Days",
    age>=30,"6_Older than 30 Days",
    age>=20,"5_Older than 20 Days",
    age>=10,"4_Older than 10 Days",
    age>=5,"3_Older than 5 Days",
    age>=2,"2_Older than 2 Days",
    0==0,"7_No Age Data")

View solution in original post

0 Karma

manjunathmeti
Champion

hi @mbasharat, For timezone (UTC) you can set variable "%Z".

Try this:

| makeresults 
| eval Event_Created_Time_Date="2019-10-08 15:24:40.132 UTC" 
| eval age=ceiling((now() - strptime(Event_Created_Time_Date, "%Y-%m-%d %H:%M:%S.%3N %Z"))/86400) 
| eval Event_Age=case(
    age<1,"1_Less than 1 Days",
    age>=30,"6_Older than 30 Days",
    age>=20,"5_Older than 20 Days",
    age>=10,"4_Older than 10 Days",
    age>=5,"3_Older than 5 Days",
    age>=2,"2_Older than 2 Days",
    0==0,"7_No Age Data")
0 Karma

mbasharat
Builder

THANK YOU!!!

0 Karma
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 ...