Reporting

How to add time to an event

Mary666
Communicator

Hello Splunk Community,

I have read through the Q&A 7 pages in and read through several instructions on how to do this, but still cant seem to find what I need to do. I am trying to add 1 hr and 15 min to the event latestEvent. Can obtain some guidance on how to add 1 hr and 15 min to a field? In this case the filed is latestEvent. 

(index="xyz" event=submission ) OR (index="abc )
| eval latestEvent=case(event="submission", timeofsub)
| eval Scheduled_Ingestion_Time=relative_time(latestEvent, "+3615")
| stats  latest(latestEvent) as latestEvent values(Scheduled_Ingestion_Time) as Scheduled_Ingestion_Time  

 

Tags (1)
0 Karma
1 Solution

tscroggins
Influencer

@Mary666 

You have a few options, but the two simplest ones are:

To convert the field back to a string:

| eval Scheduled_Ingestion_Time=strftime(strptime(latestArchive, "%Y-%m-%d %H:%M:%S.%3N") + 4500, "%Y-%m-%d %H:%M:%S.%3N")

To leave the field an integer but display it as a string:

| eval Scheduled_Ingestion_Time=strptime(latestArchive, "%Y-%m-%d %H:%M:%S.%3N") + 4500

| fieldformat Scheduled_Ingestion_Time=strftime(Scheduled_Ingestion_Time, "%Y-%m-%d %H:%M:%S.%3N")

The time function names can be read as "string from time" and "string parse time."

View solution in original post

tscroggins
Influencer

@Mary666 

Timestamp fields like _time are integer Unix epoch values: the number of seconds elapsed since January 1, 1970 12:00 AM.

To add 1 hr and 15 min to a time field, add 4500 seconds:

| eval Scheduled_Ingestion_Time=latestEvent + 4500

If latestEvent isn't a time field, you'll need to convert it to one using whatever method is appropriate for your data. For example, if latestEvent is the string "2021-03-05 00:00:00" you would use:

| eval Scheduled_Ingestion_Time=strptime(latestEvent, "%F %T") + 4500

0 Karma

Mary666
Communicator

Hi tscroggins,

 

Thanks for your quick reply. I tried your recommendation and it helped using | eval Scheduled_Ingestion_Time=strptime(latestEvent, "%F %T") + 4500 , but I have a question:

1.  I only seem to get results in epoch time example: 

The time  I get is:  1613751347.000000
But I would like to convert it to Unix: 2021-02-19 07:00:47.089586 

I have tried using  | eval Scheduled_Ingestion_Time=strptime(latestArchive,"%Y-%m-%d %H:%M:%S.%3N") + 4500

Still get epoch time though.  Any guidance on how to tackle this will greatly help. 

 

0 Karma

tscroggins
Influencer

@Mary666 

You have a few options, but the two simplest ones are:

To convert the field back to a string:

| eval Scheduled_Ingestion_Time=strftime(strptime(latestArchive, "%Y-%m-%d %H:%M:%S.%3N") + 4500, "%Y-%m-%d %H:%M:%S.%3N")

To leave the field an integer but display it as a string:

| eval Scheduled_Ingestion_Time=strptime(latestArchive, "%Y-%m-%d %H:%M:%S.%3N") + 4500

| fieldformat Scheduled_Ingestion_Time=strftime(Scheduled_Ingestion_Time, "%Y-%m-%d %H:%M:%S.%3N")

The time function names can be read as "string from time" and "string parse time."

Mary666
Communicator

Thanks, 

| eval Scheduled_Ingestion_Time=strftime(strptime(latestArchive, "%Y-%m-%d %H:%M:%S.%3N") + 4500, "%Y-%m-%d %H:%M:%S.%3N") 

 

Did the trick 🙂 

 

 

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