icon/x Created with Sketch.

Splunk Cookie Policy

We use our own and third-party cookies to provide you with a great online experience. We also use these cookies to improve our products and services, support our marketing campaigns, and advertise to you on our website and other websites. Some cookies may continue to collect information after you have left our website. Learn more (including how to update your settings) here.
Accept Cookie Policy

Accept License Agreements

This app is provided by a third party and your right to use the app is in accordance with the license provided by that third-party licensor. Splunk is not responsible for any third-party apps and does not provide any warranty or support. If you have any questions, complaints or claims with respect to this app, please contact the licensor directly.

Thank You

Downloading Time Macros
SHA256 checksum (time-macros_102.tgz) 36dff8083e23d23b550345a4b4fcf17dfafe2aa6844eeb7f7846245fae8ad99d SHA256 checksum (time-macros_101.tgz) b3430d3451f4b0b5f6efca55d39485b6d98a3ea0d22a81d08fe0a676bfab2fb1 SHA256 checksum (time-macros_100.tgz) e9f7c77041a9399db579116c1614c8f50dee39c9e10eb415efc40d4597a69b31
To install your download
For instructions specific to your download, click the Details tab after closing this window.

Flag As Inappropriate

Time Macros

Splunk AppInspect Passed
Admins: Please read about Splunk Enterprise 8.0 and the Python 2.7 end-of-life changes and impact on apps and upgradeshere.
The Time Macros app provides a set of globally shared eval based macros for doing time maths. For a long-form motiviational take on this see @duckfez' blog post: https://www.duanewaddle.com/searching-date-time-values-in-splunk/

See the Details tab up top for a list of macros and their description as well as real-world usage examples.

Supported Macros

As of 1.0.0, these are included:

  • tm_relative_time(epoch, relative) wraps the relative_time() eval function to shift an epoch time by a relative time modifier.
  • tm_strptime(timestr, format) wraps the strptime() eval function to convert a formatted time string to an epoch.
  • tm_strftime(epoch, format) wraps the strftime() eval function to convert an epoch into a formatted time string.
  • tm_trp2epoch(trp) converts the output of a timerangepicker into an epoch.
  • tm_relative_trp(trp, relative) combines tm_trp2epoch() with tm_relative_time(), it converts a timerangepicker output into epoch and then shifts that by a relative time modifier. Combining two macro calls like you would combine function calls in eval is not a thing, that's why a whole new macro is needed.

Known Issues

  • The macros use time() instead of now() for relative time calculations due to eval macro restrictions. In most scenarios relative time modifiers snapping to an hour, a day, etc. smooth over this difference. Keep it in mind if you manually override the value of now, such as when re-running old summary searches with fill_summary_index.py!

Usage Examples:

Let's say your events contain an expiration_date field in epoch, and you want to find things that expired before August 1st 2020 in your user timezone:
index=foo sourcetype=bar expiration_date < `tm_strptime("2020-08-01", "%F")` | ...
This is converted to normalizedSearch/phase0 expiration_date<1596232800.000000 (see Job Inspector), and will use a lispy-based filter powered off tsidx files if expiration_date is declared as an indexed field for massive speed benefits.

If you used subsearches to do this calculation in the past, Time Macros is for you! Example by @jeffland:
Old style: index=foo some_epoch_field >= [| makeresults | eval search = relative_time(now(), "-1h@h")]
Time Macro style: index=foo some_epoch_field >= `tm_trp2epoch("-1h@h")`
Instead of launching a whole new search process to do one simple calculation, the eval-based macro will do the calculation during search expansion for virtually no added execution time.

Release Notes

Version 1.0.2
Sept. 4, 2020

Now with more AppInspect \o/

Version 1.0.1
Sept. 4, 2020

Now with more AppInspect \o/

Version 1.0.0
Aug. 26, 2020

Initial release with five time macros


Subscribe Share

AppInspect Tooling

Splunk AppInspect evaluates Splunk apps against a set of Splunk-defined criteria to assess the validity and security of an app package and components.

Are you a developer?

As a Splunkbase app developer, you will have access to all Splunk development resources and receive a 10GB license to build an app that will help solve use cases for customers all over the world. Splunkbase has 1000+ apps and add-ons from Splunk, our partners and our community. Find an app or add-on for most any data source and user need, or simply create your own with help from our developer portal.

Follow Us:
© 2005-2020 Splunk Inc. All rights reserved.
Splunk®, Splunk>®, Listen to Your Data®, The Engine for Machine Data®, Hunk®, Splunk Cloud™, Splunk Light™, SPL™ and Splunk MINT™ are trademarks and registered trademarks of Splunk Inc. in the United States and other countries. All other brand names, product names, or trademarks belong to their respective owners.