Skip to content

Instantly share code, notes, and snippets.

@robws
Last active October 29, 2022 14:44
Show Gist options
  • Save robws/67af6c11969475f41aa33ac0c724ccbe to your computer and use it in GitHub Desktop.
Save robws/67af6c11969475f41aa33ac0c724ccbe to your computer and use it in GitHub Desktop.
set up shortcuts to generate the date and time in different formats
/*
Date/time hotstrings
If you want the date/time in the format yyyymmdd_hhMM on 10/29/2022 at 10:37 AM, type:
dtm
You should see:
20221029_1037
To add your own:
1. Decide on your hotstring (e.g. tst)
2. Add your hotstring to the top of the hotstring list (line 18):
:?*:tst::
{remaining hotstrings}
3. Add your hotstring with a date/time mask to the DateTimeFormats list (insert at line 37, for example)
,"tst":"h:mm tt"
4. Reload the script
5. Test your hotstring:
If it's 10:43 AM, for example, and you type:
tst
You should see:
10-43 AM
*/
:?*:dtm::
:?*:dt;::
:?*:md;::
:?*:tss::
:?*:sd;::
:?*:ttt::
:?*:tts::
:?*:mdu::
:?*:mdf::
:?*:mdd::
sendFormattedDate() {
placementKey := regexmatch(A_thishotkey,"O)md([a-zA-Z;]+)",matches)?matches[1]:""
dateTimeCode := regexmatch(A_thishotkey,"O):\?\*:([a-zA-Z;]+)",matches)?matches[1]:""
DateTimeFormats := {"mdd":"yyyy-MM-dd"
,"dtm":"yyyyMMdd_HHmm"
,"sd;":"MM-dd_HH-mm"
,"ttt":"HHmm"
,"tss":"HH-mm tt"
,"th;":"HH:mm"
,"dt;":"yyyy-MM-dd"
,"md;":"yyyy-MM-dd"
,"mds":"yyyy_MM_dd"
,"mdu":"h:mm tt"
,"mdf":"yyyy-MM-dd h:mm tt"
,"mddx":"MMdd"}
formatstring := DateTimeFormats[dateTimeCode]
FormatTime,thisFormattedTime,,%formatString%
prefix:=(dateTimeCode=="ttt")?"ts":""
suffix:=(dateTimeCode=="ttt")?" ":""
dateTimeString:=prefix . thisFormattedTime . suffix
SendInput, % dateTimeString
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment