Ben Nieting
Ben Nieting

Reputation: 1520

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

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

Upvotes: 90

Views: 108997

Answers (13)

eric
eric

Reputation: 925

From https://superuser.com/questions/1278798/how-to-insert-date-time-in-notepad-64bit

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.

Upvotes: 0

Uxoos
Uxoos

Reputation: 21

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

screenshot: https://i.sstatic.net/1368s.png

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

Upvotes: 1

not2qubit
not2qubit

Reputation: 17027

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

Upvotes: 12

jciloa
jciloa

Reputation: 1137

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.

Upvotes: 4

Ben Nieting
Ben Nieting

Reputation: 1520

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

Upvotes: 25

Frank
Frank

Reputation: 515

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.

Upvotes: 3

pbarney
pbarney

Reputation: 2843

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.

Upvotes: 0

Stephan Kolassa
Stephan Kolassa

Reputation: 8267

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

Upvotes: 7

lode
lode

Reputation: 564

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

Upvotes: 1

devinbost
devinbost

Reputation: 5084

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

Upvotes: 54

BoltClock
BoltClock

Reputation: 724342

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.

Upvotes: 66

iCrazybest
iCrazybest

Reputation: 3115

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

Insert Date & Time in Notepad++

Upvotes: 65

jxramos
jxramos

Reputation: 8276

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

Upvotes: 5

Related Questions