When you’re writing content such as technical content, news articles, etc., you may sometimes want to insert the current date or timestamp in a program or editor you’re using. In Notepad, you can add the timestamp by pressing the F5 key.
Microsoft Office Word, OneNote allows the Alt + Shift + D and Alt + Shift + T hotkey combinations to insert the current date and current time respectively.
Similarly, WordPad has the Date and time toolbar button that lets you insert the date or timestamp in your preferred format from the list of 13 choices.
But, if you’re using a program which doesn’t have a built-in feature to insert current date and time, you may need a third-party macro or automation tool for that purpose. With automation tools, you also have the advantage of using a single hotkey combination to insert the date or timestamp in any program.
Insert date or time in any program using keyboard hotkey
AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts for all kinds of tasks such as form fillers, auto-clicking, macros, etc.
- Download AutoHotkey and install it.
- Right-click on the desktop, click New and select AutoHotkey Script.
- Rename the script file
New AutoHotkey Script.ahkto
- Right-click the file and choose Edit Script
- Remove all lines in the script and replace it with the following code:
^!d:: FormatTime, CurrentDateTime,, hh:mm tt M/dd/yyyy SendInput, %CurrentDateTime% return
- Save the file
insert_date.ahkand close the editor.
- Double-click to run the script. It will show up in the notification area.
- Now, switch to the program where you want to insert the date or timestamp.
- Press Ctrl + Alt + D to insert the timestamp at the current cursor position.
You can change the keyboard hotkey in the (1st line of the) script if you need. Here are the modifiers.
For example, for Ctrl + Alt + Shift + D, you’d use
For the full list of keys you can send or intercept, see AutoHotkey SendInput documentation
Without using hotkeys
If you want to insert the timestamp by typing a specific word — e.g.,
td, then edit the .ahk script and replace its contents with the following:
::td:: FormatTime, CurrentDateTime,, hh:mm tt M/dd/yyyy SendInput, %CurrentDateTime% return
td (and followed by a space) in any program. The words
td will be replaced by the current date/timestamp. See this animation:
Similarly, you can customize the Date or timestamp format.
|hh:mm tt M/dd/yyyy||11:26 AM 6/15/2019|
|hh:mm tt MM/dd/yyyy||11:26 AM 06/15/2019|
|hh:mm:ss tt MM/dd/yyyy||11:26:22 AM 06/15/2019|
|HH:mm MM/dd/yyyy||11:26 06/15/2019|
|HH:mm MMM/dd/yyyy||11:26 Jun/15/2019|
|(no formatting)||11:26 AM Saturday, June 15, 2019|
See FormatTime Syntax AutoHotkey documentation for more information.
The above AutoHotkey script uses merely
1.5 MB of memory.
And you can even compile the .ahk script to a .exe file so that you don’t need to have the AutoHotkey program installed. This is especially helpful if you manage a lot of computers as part of your home or work network.
One small request: If you liked this post, please share this?One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
- Pin it!
- Share it to your favorite blog + Facebook, Reddit
- Tweet it!
7 thoughts on “Insert Date/Time in Any Program Using Keyboard Hotkey”
how do you include ONLY the date???
Adjust the format string to remove the time parameters:
FormatTime, CurrentDateTime,, M/dd/yyyy
Thank you Ramesh Srinivasan,
An excellent introduction to AutoHotKey.
Almost what I need, so I thank you. Problem is that I am working in a WordPress form and, when I use this, nothing is inserted. I tried changing the hotkeys. It seems to be impervious to the insertion process.
Pasting, however, does work. So I run this with notepad open and copy it, then paste it into the form. Works, though rather slow. I did modify the program so that it automatically highlights and then copies the output.
Mainly, I would like to find a way to divorce it from needing a third program to paste the output into. I could have it open notepad, do its thing, and then close notepad,, but that would be really slow.
Is there any way to have ahk write the output directly onto the clipboard?
I get error at line 2.
function requires call or space or ( etc
@para: This may have to do with the AHK version (v1 vs v2). Check out this Reddit link for more information:
Function calls require a space : AutoHotkey:
Excellent tutorial, and a great introduction to ahk
but how do I make it into the dd/mm/yy format?