Working with AutoHotkey Date Formats and Timespan Calculations

AutoHotkey Date and Time Calculations Require Special Handling—Check Out This List of How-to’s for Working with Dates

Over the years, I’ve written a number of blogs and many chapters about formatting and calculating dates, but one of my AutoHotkey apps that I think most demonstrate the full range of these capabilities include the scripts HowLongYearMonthDay.ahk and DateConvert.ahk.

When combined with the HowLongYearMonthDay.ahk script, the DateStampConvert.ahk script directly converts various ambiguous date formats selected in documents or Web pages into the standard datetime stamp format for inserting into the time-span calculating GUI pop-up.

Rather than using AutoHotkey commands for converting the standard datetime stamp into one of the numerous worldwide date formats, this conversion tool does the reverse and reformats selected dates into the universal datetime stamp.

Most AutoHotkey date commands and functions emphasize how to convert from the standard datetime stamp (YYYYMMDDHH24MISS) into the various global date and time text formats (e.g. US, European, etc.) found in documents. However, when using specialized GUI controls such as the DateTime and MonthCal, we find that they only accept input in that standard datetime format. That means we must convert those various document date formats before we can use them in our apps. AutoHotkey offers no simple tools for converting the wide variety of common date formats into the year-month-day string.

Referenced in the AutoHotkey documentation, the forum link “Date parser – convert any date format to YYYYMMDDHH24MISS” provides a Regular Expression (RegEx) for doing the job. However, due to the ambiguity of many date formats, it falls short when distinguishing between US and European all-numeric date formats for the first 12 days of any given month. I address this problem and possible answers in the DateStampConvert.ahk script discussed in a couple of the blogs listed on the page referenced below.

To make it easier for those exploring date conversion/calculation issues in AutoHotkey, I’ve published a new page listing blogs addressing the topic: “Date Formats and Calculations in AutoHotkey.” (You can locate the page via the menu bar item “AutoHotkey Topics and Series” found at the top-right of this page—or click the link.) Whether inserting a date format into a document, calculating next Friday’s date, doing the conversions and timespan work mentioned above, or adding dynamic menus with multiple date formats to any pop-up, you’ll find detailed discussions in these blogs.

Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)


This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

Find my AutoHotkey books at ComputorEdge E-Books!

Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!

2 thoughts on “Working with AutoHotkey Date Formats and Timespan Calculations

  1. hi! is it possible to highlight the entire date range (E.g. 16-March-2021 to 21-May-2021) when hotkey is triggered, feed it into the timespan ahk and share the time span as result?

    Also, do you mind sharing the script for reference? Thanks!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s