1

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

James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

1

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

Yutaka
  • 1,761
  • 2
  • 5
  • 9
  • Thank you! I works only using the American date format. How will the formula work for dd/MM/yyy date format? – Ayemoighe Omu Jul 21 '22 at 18:11
  • It should work fine with dd/MM/yyyy as long as the system date format is also dd/MM/yyyy. Did you check Windows locale settings? – Yutaka Jul 21 '22 at 20:07
0

In a single line, you may execute it in this way:

parseInt(txt.split(',').map(x => x = new Date(x)).map((a,b,ar) => Math.abs(a-ar[i+1])).shift()/(1000 * 60 * 60 * 24), 10)

Code:

const txt = '1/1/2022,12/31/2022';
console.log(parseInt(txt.split(',').map(x => x = new Date(x)).map((a,b,ar) => Math.abs(a-ar[i+1])).shift()/(1000 * 60 * 60 * 24), 10));

Output:

364
Art Bindu
  • 769
  • 4
  • 14