I need to format dates and times like the ones provided in order to create a column displaying the time elapsed since each specific date.
The issue you're facing doesn't seem to be a real problem.
Let's break it down manually. From 2nd February 2023 08:53:49 to 28th March 2023 11:31:59:
From 2nd February to 28th March - 2023-02-02T00:00:00 to 2023-03-28T00:00:00 is a span of 54 days.
From 08:53:49 to 11:31:59, there are 2 hours, 38 minutes, and 10 seconds.
Adjusting for daylight saving time, we have 1 hour, 38 minutes, and 10 seconds.
This total duration converted to seconds equals 4,671,490 seconds.
Now let's see how JavaScript handles this calculation
const start = new Date('2023-02-02T08:53:49+0100'); // +0100 for Central European Standard Time
const end = new Date('2023-03-28T11:31:59+0200'); // +0200 for Central European Summer Time
const seconds = (end - start) / 1000;
console.log(seconds);
The result matches our manual calculation.