Calculating Dates in AutoHotkey by Adding Years, Months, and/or Days

The HowLongYearsMonthsDays.ahk Script Calculates Time Spans—This New DateCalc() Function Yields New Dates Based on Adding or Subtracting Years, Months, or Days

Allan recently inspired me to write (and helped me debug) an AutoHotkey function for calculating new dates based on entering years, months, and/or days. While not long or involved, the function includes a couple of interesting techniques.

Note: I have no doubt that many others have written similar date-calculating functions in AutoHotkey. This merely represents my stab at it.

The lack of consistency in days between 12-month years (leap years) and the varying numbers of days in months underlies the basic date calculating problem. While AutoHotkey includes a special tool (EnvAdd) for determining new dates based upon adding days, hours, minutes, or seconds to any valid date-time stamp format, writing a more complete date finding function requires accounting for the year and month variables separately.

Continue reading

Using Parts to Build a New AutoHotkey Script (HowLongInstant.ahk)

While Many Users Find the Original GUI Based HowLong Script Valuable, Combining Snippets of Code Creates a New Instant HowLong Script

Last time in “Extracting Multiple Dates from Text Using AutoHotkey RegEx,” I wrote a Regular Expressions (RegEx) that copied the first and last date (in a variety of formats) found in a selection from a document or Web page. (I recently updated that RegEx to make it more robust.) That represented the first step in building an instant HowLongYearsMonthsDay.ahk script. The goal, as defined by the reader, included highlighting a section of text which bounds two dates, pressing a Hotkey combination, then immediately calculating and displaying the timespan—no delaying the process with an input GUI or clicking a calculate button. As with many new scripts, I took pieces of it from other scripts and integrated them to produce a new one.

The chunks I used to produce the new script included:

  1. The Standard Clipboard Routine for capturing the selected text.
  2. The RegEx for identifying and capturing the target dates. (Discussed in my last blog.)
  3. The DateConvert() function found in the DateStampConvert.ahk script for formatting the parsed dates as the standard TimeDate stamp (YYYYMMDD).
  4. The HowLong() function found in the HowLongYearsMonthsDays.ahk script for calculating the timespan between the two TimeDate stamp parameters.
  5. A MsgBox for instantly displaying the results.
Continue reading

AutoHotkey Tip of the Week: Instant Upper Case, Lower Case, and Initial Cap Text—September 2, 2019

Tips: Quick Hotkeys for Changing Text To/From Capital Letters and How to Initial Cap Everything, Plus, How to Write Robust Clipboard Routines

Light Bulb!This week I offer two useful tips: one for editing text and the other for improving your AutoHotkey scripts.

When reviewing my books, I look for those tips which I use all the time. I’ve found that I developed some scripts primarily for demonstration purposes and rarely ever use them again. Yet, I have a few which I use so much that I feel like they have become a part of my Windows system.

AHKNewCover200In this case, while perusing my Beginner’s Guide to AutoHotkey, I noticed in “Chapter Four: Hotkeys and Text Editing with Windows Clipboard” the Hotkeys for changing selected portions of text into all capital letters, all lowercase letters, or initial cap every word in the section. I originally wrote these Hotkeys when I edited articles submitted by freelance writers.

Some writers have a penchant for placing their article headlines and topic subheadings in all uppercase letters. By creating a Hotkey for converting the entire line to Title Mode (initial capital letter for each word), I quickly solved the retyping problem:
Continue reading