Kudos
I’ve been keeping some form of a work journal for years; I’d highly recommend it. I recently got annoyed with creating timestamps in Notepad++, and ran across a helpful post in a forum. It was so helpful that I thought I’d do my best to try to give it some additional street cred.Here is the original link:
http://sourceforge.net/p/notepad-plus/discussion/331753/thread/3458d1da#62f2
What day of the week was 4/22/2006 anyway?
Before I start, if you have the TextFX plugin already setup in Notepad++, it provides 2 static methods of inserting a datetime stamp:Menu: TextFX > TextFX Insert > I:Date & Time: short format: 3:56 PM 3/22/2013
Menu: TextFX > TextFX Insert > I:Date & Time: long format: 3:56 PM Friday, March 22, 2013
If these look good enough to you, you can skip to the section on how to map a keyboard shortcut to these. However, in addition to the time and date, I also wanted the day of the week, like this: 03:36 PM 03/22/2013 (Friday)
Steps
It turns out this can easily be done with a simple Python script. I don’t even know Python that well and I was able to do it.1. Install the python plugin:
- The plugin’s name is: Python Script
- It’s recommend you do this via the NP++ Plugin Manger (Menu: Plugins > Plugin Manger)
- Here’s a link to the project page: http://npppythonscript.sourceforge.net/
- The script includes some basic Python libraries, so you shouldn’t need to install Python or other 3rd party libraries
2. Setup script in Notepad++:
- Menu: Plugins > Python Script > New Python Script
- It will ask you for a new file name, I choose: npp_timedate_stamp.py
- A new tab will appear in NP++ for you to enter the script.
- This is the script I used:
# Add date/time stamp in Notepad++ 03:28 PM 03-22-2013 (Friday) import time editor.addText( time.strftime( '%I:%M %p %m/%d/%Y (%A) ' ) )
- Here is a link to the Python documentation which shows what all the format string characters: http://docs.python.org/2/library/time.html
- Save your script
3. Configure Notepad++ to use the script:
- Menu: Plugins > Python Script > Configuration
- You should see your script under the User Scripts section
- Add it to Toolbar and/or Menu
- I put it in both, but I only managed to find it under menu
- It shows up as its own entry under Menu: Plugins > Python Script > npp_timedate_stamp
4. Create a keyboard shortcut (my preferred method):
- Menu: Settings > Shortcut Mapper
- Switch to Plugin
- Scroll down until you see your script name (i.e. npp_timedate_stamp)
- Click on it, choose Modify, and choose a key. I used: CTRL + ;
Hello Jason,
ReplyDeletethanks for your post.
I ve been looking for something like this since a while. Your solution works perfect for me.
Comments:
- I had to restart NP++ to find my script name in the Shortcut Mapper
- For anyone interested: use '%d.%m.%Y %H:%M:%S' to get following output: 10.04.2013 09:52:45
Thanks again, Peter
Thanks for the feedback Peter!
ReplyDeleteExcellent work and explanation! This is just what I needed for my note-taking during calls.
ReplyDeleteThanks, Rick
What versions of Notepad++ and Python Script plugin are you guys using? Because this isn't working for me. First time I trigger the script, nothing happens at all. Second time, I get a popup telling me that a script is already running. "Stop Script" doesn't seem to have any effect either.
ReplyDeleteI'm running Notepad++ 6.3.3 and Python Script plugin 0.9.2.0 with Python 2.7.1 (release27-maint-npp, Feb 6 2011, 16:58:20) [MSC v.1500 32 bit (Intel)]
Nevermind, sorry for the noise.
ReplyDeleteThe problem was that Python Script plugin was installed into user's %APPDATA, which doesn't seem to work. All is fine after moving it to the application install location...
Glad you were able to figure it out. I double-checked my setup and my script is in the %APPDATA folder. I'm not sure what the problem is, but I also don't want to cause you any extra work!
ReplyDeleteNice post! I have just added this to my NotePad++, and it works great! I did have to restart NotePad++ in order to see my script in the Shortcut Mapper, but after that everything was fine!
ReplyDeleteThanks for the note!
ReplyDeleteHi Jason,
ReplyDeleteThanks for this blog - helped me out - nice work!
Great post. I used the guide to generate ISO 8601 timestamps with offsets (e.g. 2013-10-21T16:50:00+01:00).
ReplyDeleteGreat work, thanks.
ReplyDeleteThanks so much for posting this, this is exactly what I was looking for and it works great!
ReplyDeleteThanks for this, I've created a script that automatically adds a new entry to my work journal in MarkDown format that includes the datestamp and a few preformatted headings. I love that so many programs now have Python APIs.
ReplyDeleteAwesome! I too have been looking for exactly this since I started using Npp.
ReplyDeleteIt's also a starting point for learning a little remedial Python...
Thank you very much.. Was really helpful..
ReplyDeleteIs there a way to use this to save a file as today's date? Thank you in advance.
ReplyDeleteTry a variation of this command:
Deleteimport time
notepad.saveAs( time.strftime('%I%M %p %m-%d-%Y (%A).txt') )
You must pay attention to which folder it will try to save to.
THANK YOU!!! This works like a charm!
ReplyDeleteQuick tip, doing editor.clear() first lets u overwrite any selected text
ReplyDelete.LOG in notepad
ReplyDelete