82

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++?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ben Nieting
  • 1,360
  • 2
  • 14
  • 23
  • 4
    This isn't a programming related question.. – austin wernli Jan 14 '15 at 19:17
  • There are some similar questions on [Super User](http://superuser.com/questions/299796/how-to-insert-time-and-date-and-the-directory-path-in-notepad). If this exact question doesn't exist there, you can ask it there. – ryanyuyu Jan 14 '15 at 19:20
  • 4
    interesting point, do questions on programming/development tools qualify for SO questions? – jxramos Jan 14 '15 at 19:23
  • 4
    @jxramos: They do. There's just not a whole lot of "programming" to be had here though. I mean, you don't usually use an IDE like Visual Studio for anything *but* development, whereas Notepad++ advertises itself as both a code editor and a straight-up Notepad replacement. – BoltClock Jan 14 '15 at 19:24
  • F5 does not work in Notepad on Windows 10 (neither does [the ".LOG" trick](https://www.tech-recipes.com/rx/909/windows-notepad-insert-time-and-date-into-text-or-log-file/)). – Peter Mortensen Mar 15 '19 at 20:56
  • 1
    @PeterMortensen, I just verified that F5 still works today on my Windows 10 box. '11:51 AM 2019-03-22'. – Ben Nieting Mar 22 '19 at 18:54
  • Works on my Win10 box as well. – Mladen B. Jul 21 '21 at 22:31

13 Answers13

66

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.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
65
Step 1 : Install plugin TextFX
Step 2 : Insert Date & time

Insert Date & Time in Notepad++

iCrazybest
  • 2,935
  • 2
  • 24
  • 24
52

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++

Community
  • 1
  • 1
devinbost
  • 4,658
  • 2
  • 44
  • 57
  • 5
    Since TextFX dosen't work anymore with new versions of notepad++, this solution works on new 64 bit notepad++, thank you! – Rebelss Oct 04 '18 at 15:45
  • 1
    For installing, i found these instructions to work (i.e. to be up-to-date) for a 64-bit install: https://notepad-plus-plus.org/community/topic/17256/guide-how-to-install-the-pythonscript-plugin-on-notepad-7-6-3-7-6-4-and-above – jr-juxtaposition Aug 08 '19 at 18:27
  • 2
    I would +100 if it was possible! Once you install PythonScript and start using it (cca 20 minutes to get comfortable) you will never go back to the old ways! – dizarter Nov 22 '19 at 23:01
  • 3
    I would just say to try the Plugins Admin first. It is almost instant, very easy, seems like it should be the best integration. as of 2019 I have tried it on a dozen systems including an Ubuntu snap install and it has always worked flawlessly. – Dennis Dec 19 '19 at 13:43
  • 1
    Great answer. For assigning hotkeys, Time wasn't showing up in the Plugin Commands. So I had to first go to the Plugins --> Python Script --> Configuration and add Time.py to the "Menu" box. After restarting Notepad++, Time.py showed up in plugin commands. – abagh0703 Nov 21 '20 at 20:06
19

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).

Ben Nieting
  • 1,360
  • 2
  • 14
  • 23
  • 2
    I've recorded a macro using the macro recording feature and then saved this macro with keyboard shortcut Ctrl+Alt+D, now when I use this key combination, it inserts the current date/time at the cursor position. – Dustin Oct 28 '22 at 16:22
7

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
Stephan Kolassa
  • 7,953
  • 2
  • 28
  • 48
  • Thanks, it's easier than writing a python script, like the currently most upvoted alternative answer to TextFX suggests.Let's hope this demo plugin will stay that way... – Melvyn Oct 09 '20 at 14:36
7

In one of the recent N++ updates, my previous shortcut of CTRL + SHIFT + D, stopped working. I then rechecked and had to remap the custom date shortcut to ALT+ SHIFT + D. This is how it looks:

enter image description here

Make sure your customized date match your expectations:

enter image description here

not2qubit
  • 14,531
  • 8
  • 95
  • 135
5

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

jxramos
  • 7,356
  • 6
  • 57
  • 105
4

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.

jciloa
  • 1,039
  • 1
  • 11
  • 22
3

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.

Frank
  • 505
  • 5
  • 14
0

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
lode
  • 504
  • 6
  • 21
  • Autohotkey is like a Swiss Army Knife. Unquestionably a "required tool" and every single power user should be using it! Been using it for about two years now and I can't believe I overlooked it for so long. Thanks for the script! – pbarney Jan 23 '23 at 17:03
0

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.

pbarney
  • 2,529
  • 4
  • 35
  • 49
  • Looks cool, but it appears that the zip file to install FingerText points to a dead SourceForge link. So I can't install FingerText. – Ben Nieting Aug 04 '20 at 23:39
  • 1
    Yeah, looks like the project is dead, but I still find it very useful. Is it not available through the Plugins Admin dialog? You can also download it directly from https://downloads.sourceforge.net/project/fingertext/Alpha%20Releases/FingerText%20-%200.5.60.zip – pbarney Aug 05 '20 at 14:09
  • I get a 502 for that link. Maybe it's my firewall? The Plugins Admin uses the same link. Thanks for the suggestions. It does look cool. – Ben Nieting Aug 05 '20 at 19:19
  • 1
    Yeah, that's strange. I just confirmed it worked for me. Here is a direct link to one of the sourceforge mirrors: https://managedway.dl.sourceforge.net/project/fingertext/Alpha%20Releases/FingerText%20-%200.5.60.zip And failing that, well, if you don't mind downloading a binary from a random person on the internet, I uploaded it to https://filebin.net/984d8v81rsgh59xo and the link will last for a week. – pbarney Aug 06 '20 at 01:23
0

Click native "Menu->Edit->Insert->Date time"

screenshot: https://i.stack.imgur.com/1368s.png

Bind to key in "Menu->Settings->Shortcut mapper"

Uxoos
  • 11
  • 2
-4

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

Mladen B.
  • 2,784
  • 2
  • 23
  • 34