Round time to nearest :05


#1

Hi there,

I have created a short macro to insert the current time when a hotkey is pressed however I need to round the time up to the nearest :05. I have tried using the ROUND function but am not sure exactly how it works, currently using the %ShortTime% function to insert the time

Thanks!


#2

The ROUND() function won't work here. Instead, you need to use the MOD operator.
But it is fairly complicated, especially because we have to account for rounding up to 60 minutes, from AM to PM, and from PM to AM.

Here's a Macro to get you started. I think I have accounted for all of the above, but you need to do your own testing to ensure it works as expected.

Example Output

image


MACRO:   Round Time to Nearest 5 Minutes [Example]

~~~ VER: 1.0    2019-03-12 ~~~

DOWNLOAD:

Round Time to Nearest 5 Minutes [Example].kmmacros (16 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Round the Time in %ShortTime% to Nearest 5 Minutes

REQUIRES:

  1. KM 8.2+
  2. macOS 10.11.6 (El Capitan)
  • KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees. :wink:

NOTICE: This macro is just an Example

  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.

How To Use

  1. Just Trigger this macro.

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. ??
      .
  1. Assign a Trigger to this maro..
  2. Move this macro to a Macro Group that is only Active when you need this Macro.
  3. ENABLE this Macro.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)
    • NONE Required

TAGS: @Time @Date @MOD @Modulo

USER SETTINGS:

  • Any Action in magenta color is designed to be changed by end-user

ACTION COLOR CODES

  • To facilitate the reading, customizing, and maintenance of this macro,
    key Actions are colored as follows:
  • GREEN -- Key Comments designed to highlight main sections of macro
  • MAGENTA -- Actions designed to be customized by user
  • YELLOW -- Primary Actions (usually the main purpose of the macro)
  • ORANGE -- Actions that permanently destroy Variables or Clipboards,
    OR IF/THEN and PAUSE Actions

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

image


#3

Thank you for putting the time into making this macro, it worked perfectly!