Reputation: 29
In Emeditor, how do i get the number of days between 2 date columns? Example:
-> Column C: 4 days
Upvotes: 1
Views: 107
Reputation: 1994
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
Upvotes: 0
Reputation: 1806
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).
Select the 3rd empty column by clicking the 3rd column heading.
Press Ctrl+H to show the Replace dialog box, and enter
.*
\J d1=new Date(cell(-2)); d2=new Date(cell(-1)); diffTime=Math.abs(d2-d1); Math.ceil(diffTime / (1000*60*60*24));
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
Upvotes: 1