Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Notepad++ has a convenient timestamp facility built-in with the choice of short or long formats, but both use the built-in date format of the computer they're on, showing either the month first (if U.S.) or the day first (if U.K./Europe).

I work in both the U.S. and Europe, and the constant switching of the month and day becomes a bit disconcerting, especially when looking through logs or notes.

Am wondering if there is an easy way -- either through an existing facility, or perhaps using a macro of some kind -- to get an equally quick timestamp generated but the international format:

YYYY-MM-DD--DAY--HH:MM

(Having the DAY of the week present is a nice extra and avoids the having to look these up later when reviewing records later.)

Example:

2012-08-19--Sun--20:30

Edit: Why this choice of format? No strict reason. The ideal solution in Notepad++ would preferably be flexible enough to allow generating a pleasing format.

share|improve this question
    
What are the dashes between DD & DAY and DAY & HH? –  Louis Aug 20 '12 at 10:10
    
The double dashes -- are to visually set-off the date from the day from the time. Seems more pleasing aesthetically than 2012-08-19-Sun-20:30. (Would like the timestamp to be a single unit of characters, hence don't want spaces...) Have edited the question accordingly. –  Assad Ebrahim Aug 20 '12 at 15:57
1  
Having done heavy coding work over the years using Notepad++ due to its out-of-the-box powerful featureset, you have no idea how many times I've wanted to be able to plug into it with a scripting language from within the GUI. Thanks for posting this! –  Ben Richards Sep 6 '12 at 20:09

1 Answer 1

up vote 5 down vote accepted

Right, I've found a way using the NppExec plugin and Ruby.

Solution:

Approach: Get an external scripting language (in this case Ruby) to return the formatted timestamp and for NppExec to receive it and insert it into the cursor location in the current file shown in Notepad++.

First configure the console :

    npe_console v+   // set console to receive output in $(OUTPUT) variable
    npe_console d+   // set current working directory to same as current file

Then in NppExec > Execute menu command, enter the following snippet:

    // Diary snippet (Generates timestamp YYYY-MM-DD--DAY--HH:MM for NPP++)
    npp_console disable     // turn console off for silent operation
         // ruby one-liner does the work
    ruby -r Date -e "dt=DateTime.now; dname = Date::ABBR_DAYNAMES[dt.wday]; puts dt.strftime(\"%Y-%m-%d--#{dname}--%H:%M\");"
    sel_settext $(OUTPUT)   // put result at cursor in current file
    npp_console enable      // restore console back to default

This uses the Ruby engine to generate the timestamp and inserts it where the cursor is in the current file in Notepad++. The result (with about a 500ms delay) is the timestamp:

    2012-08-20--Mon--20:16

Note: While this certainly does the job, if anyone has a solution that doesn't rely on anything external (in this case Ruby), that would be better.


Edit: "Productionising" the solution... (robustness and convenience)

By following the steps below, the above solution can be productionised...

A hurdle is that closing Notepad++ loses the console configuration, so this has to be setup on every re-start.

So we set up the console configuration as a script that is run automatically every time Notepad++ starts.

Then associate a keyboard shortcut (hotkey) to the diary script for convenience.

Step 1: Enter the diary code into an NppExec Excute... dialog: Plugins > NppExec > Execute..., giving it a name (you'll use that name later)

Step 1 - Enter diary code

Step 2: Enter the setup_console configuration code similarly:

Step 2 - Enter console configuration code

Steps 3, 4, 5: In Plugins > NppExec > Advanced Options, set setup_console to run at startup (3), create a Menu item for the diary code (4), and put the Menu item into the Macro menu (5):

Steps 3,4,5 - Getting it all setup

Step 6: Set a keyboard hotkey (shortcut) to the diary script: Settings > Shortcut Mapper... > Plugins, and scroll down till you find the diary script name you used...

Step 6 - Keyboard shortcut

Result: Looking under the Macros menu command, you'll see your new Timestamp command with keyboard shortcut.

Result - done

Done!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.