In Notepad++, how can I insert the current date and time?

DatetimeNotepad++

Datetime Problem Overview


On Windows Notepad.exe, I simply press F5 and it inserts the date and time like this:

> 11:05 AM 1/14/2015

Can I add similarly simple functionality to Notepad++?

Datetime Solutions


Solution 1 - Datetime

If your Notepad++ shipped with TextFX, you can find this in TextFX > TextFX Insert > Date & Time - short format, which will insert a string in the exact same format. If you don't see a TextFX menu, install it via the plugin manager and it will appear.

You can then bind it to a keyboard shortcut in Settings > Shortcut Mapper... > Plugin Commands. Look for I:Date & Time - short format in the mappings.

Solution 2 - Datetime

Step 1 : Install plugin TextFX
Step 2 : Insert Date & time

Insert Date & Time in Notepad++

Solution 3 - Datetime

Try "Python Script" plugin

I prefer to use the Python Script plugin as documented here: https://ardamis.com/2014/03/09/adding-an-insert-datestamp-or-timestamp-macro-to-notepad-plus-plus/ because it gives me total control over how I want to the datetime stamp formatting to look, and it also allows me to create macro scripts for inserting other types of values that I want to compute.

Install "Python Script" MANUALLY

Please note that you must download the Python Script plugin from http://npppythonscript.sourceforge.net/download.shtml because downloading it from the Plugin Manager in Notepad++ doesn't always work. (See this thread for details.)

Write "Time.py" script

Then you can write a simple script like this:

import time
# import sys
timeStr = time.strftime( '%Y-%m-%d' + ' @ ' + '%I:%M %p' )
# sys.stdout.write(timeStr)
editor.addText( timeStr )

You can change the format string as you wish. This allows you to have total control over the text output. (See Python 2's time.strftime documentation for details.)

Then save the script to this filename:

> "%AppData%\Notepad++\plugins\Config\PythonScript\scripts\Time.py"

Create "menu item" inside "Python Script"

Navigate here: Menu bar -> Plugins -> Python Script -> Configuration like this:

Click on configuration

Then you can add the script like this:

Add script to config

Assign hotkey

Then, when you restart Notepad++, you can assign the script to a shortcut like this by going to Menu bar -> Settings -> Shortcut Mapper -> Plugin Commands -> Time:

Add keyboard shortcut to Notepad++

Further reading

More documentation on the Python Script plugin is available here: PythonScript plugin documentation for Notepad++

Solution 4 - Datetime

It looks like the TextFX plugin proposed here is not available for 64bit any more.

The alternative as of today is to install the Notepad++ Plugin Demo plugin, which provides Date Time - short format and Date Time - long format. Map to shortcuts as desired. In my German locale, the results are, respectively:

12:10 01.07.2020
12:10 Mittwoch, 1. Juli 2020

Solution 5 - Datetime

This features has been added in Notepad++ v8.1.4.

Menu > Edit > Insert >

  • Date Time (short)
  • Date Time (long)

That answers this question without the need for a plugin.

Can you find a way to map it to a shortcut? Currently, the shortcut mapper does not have an entry to map it to. When I try to record and playback a macro for it, I get gibberish on the screen (looks like a bug).

Solution 6 - Datetime

With the TextFx add on there's an option to insert date and time. I guess you can assign a keyboard shortcut to it.

Time formats with TextFx Notepad++ addon

Solution 7 - Datetime

A simple method through LuaScript (https://github.com/notepad-plus-plus/notepad-plus-plus/issues/497 and https://www.lua.org/pil/22.1.html): install LuaScript plugin first, then in LuaScript Edit Startup Script past the following:

npp.AddShortcut("Insert Current Date/Time", "Ctrl+Shift+D", function()
	editor:ReplaceSel(os.date("%I:%M %p %m/%d/%Y"))
end)

After restart npp, the Ctrl-Shift-D will do as F5 in notepad.

Solution 8 - Datetime

Starting with Notepad++ 8.1.5, you can insert a custom date/time format using Edit/Insert/Date Time (customized). You can customize it in Settings/Preferences/Multi-Instance & Date.

Solution 9 - Datetime

A more generic answer using "Autohotkey":

https://autohotkey.com/board/topic/21387-how-to-insert-current-date-into-a-hotkey/

Examples:

;//will replace ddd keystroke with yyyy-MM-dd formatted date
:R*?:ddd:
FormatTime, CurrentDateTime,, yyyy-MM-dd
SendInput %CurrentDateTime%
return

;//will replace ttt keystroke with yyyy-MM-dd HH:mm formatted date/time
:R*?:ttt::
FormatTime, CurrentDateTime,, yyyy-MM-dd HH:mm
SendInput %CurrentDateTime%
return

Solution 10 - Datetime

Here's an easy and flexible way to insert a date/time stamp in any format you like.

Like many other developers, I used the FingerText plugin which allows you to insert customizable snippets of code or text by typing a "trigger" word and pressing the tab key.

One of my snippets is to insert a date/time stamp that I use in code comments:

I just type stamptab and it inserts a date like this: 2020-07-31 @ 11:45

Here is the FingerText code I use to generate the stamp, which you can modify for any datetime format you choose:

$[![(key)DATE:yyyy-MM-dd]!] @ $[![(key)TIME:HH:mm]!] $[0[]0][>END<]

You can download FingerText through the Plugins Admin dialog.

Solution 11 - Datetime

The quickest way that comes to my mind is to open Windows Notepad, press F5, copy/paste. No need to install anything...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen NietingView Question on Stackoverflow
Solution 1 - DatetimeBoltClockView Answer on Stackoverflow
Solution 2 - DatetimeiCrazybestView Answer on Stackoverflow
Solution 3 - DatetimedevinbostView Answer on Stackoverflow
Solution 4 - DatetimeStephan KolassaView Answer on Stackoverflow
Solution 5 - DatetimeBen NietingView Answer on Stackoverflow
Solution 6 - DatetimejxramosView Answer on Stackoverflow
Solution 7 - DatetimeFrankView Answer on Stackoverflow
Solution 8 - DatetimejciloaView Answer on Stackoverflow
Solution 9 - DatetimelodeView Answer on Stackoverflow
Solution 10 - DatetimepbarneyView Answer on Stackoverflow
Solution 11 - DatetimeMladen B.View Answer on Stackoverflow