Search code examples
emeditor

How To Get The Number Of Days Between Two Dates In Emeditor


In Emeditor, how do i get the number of days between 2 date columns? Example:

  • Column A: 25/11/2022
  • Column B: 29/11/2022

-> Column C: 4 days


Solution

  • Sample:

    1/1/2022,1/2/2022,
    1/1/2022,2/2/2022,
    1/1/2022,3/2/2023,
    

    The 3rd column must be an empty column. Assuming the date format is the system date format. In this case, it is the US format (m/d/yyyy).

    1. Select the 3rd empty column by clicking the 3rd column heading.

    2. Press Ctrl+H to show the Replace dialog box, and enter

    • Find: .*
    • Replace with: \J d1=new Date(cell(-2)); d2=new Date(cell(-1)); diffTime=Math.abs(d2-d1); Math.ceil(diffTime / (1000*60*60*24));
    • Set the Regular Expressions and In the Selection Only options.
    1. Make sure the selection (3rd column) is empty, and click Replace All.

    The result will be:

    1/1/2022,1/2/2022,1
    1/1/2022,2/2/2022,32
    1/1/2022,3/2/2023,425
    

    References