Heisenberg
Heisenberg

Reputation: 29

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 C: 4 days

Upvotes: 1

Views: 107

Answers (2)

ArtBindu
ArtBindu

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

Yutaka
Yutaka

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).

  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

Upvotes: 1

Related Questions