Search code examples
emeditor

HOW TO CONVERT ONE DATE FORMAT TO ANOTHER IN A COLUMN IN EMEDITOR


I have a File in Emeditor with date column with "December 30, 2021" & "2021-12-30" formats and i want to convert the entire column to "dd/mm/yyyy". How do i convert the entire column to my preferred format? Can you create a Macro for me?


Solution

  • Please make sure to update EmEditor version to the latest version including beta versions (v21.5.905 or later).

    1. Select a column you want to normalize dates.
    2. Press Ctrl+H to bring up the Replace dialog box.
    3. Click Number Range to bring up the Enter Number Range dialog box.
    4. Click Date/times, clear Use default date format check box, and enter yyyy-MM-dd|yyyy-M-d|MMMM dd, yyyy|MMMM d, yyyy below the check box. These are the date formats you want to search for, combined with a pipe (|).
    5. Enter appropriate dates in Minimum number and Maximum number (optional), and click OK.

    Enter Number Range

    1. In the Replace dialog box, make sure the In the Selection Only option is set.
    2. Enter \D dd/MM/yyyy in the Replace with box. This is a resultant date format.
    3. Click Replace All.

    Replace

    If you prefer macros, you can write and run a macro like this:

    document.selection.Replace("[1900-01-01 , 2100-12-31 \"yyyy-MM-dd|yyyy-M-d|MMMM dd, yyyy|MMMM d, yyyy\" ]","\\Ddd/MM/yyyy",eeFindReplaceSelOnly | eeReplaceAll,eeExFindNumberRange);
    

    To run this, save this code as, for instance, NormalizeDate.jsee, and then select this file from Select... in the Macros menu. Finally, select Run NormalizeDate.jsee in the Macros menu. You must select a column before you run this macro.

    References:

    Updates

    As of v21.5.906 or later, please remove a space after /D.