diff --git a/snippets/getDifferenceInSeconds.md b/snippets/getDifferenceInSeconds.md deleted file mode 100644 index ea30aad74..000000000 --- a/snippets/getDifferenceInSeconds.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: getDifferenceInSeconds -tags: dates,beginner ---- - -Returns the diffrence in seconds between 2 supplied dates. - -```js -const getDifferenceInSeconds = (start, end) => - (end.getTime() - start.getTime()) / 1000; -``` - -```js -getDifferenceInSeconds(new Date('2020-12-24 00:00:15'), new Date('2020-12-24 00:00:17')); // 2 -``` diff --git a/snippets/getSecondsDiffBetweenDates.md b/snippets/getSecondsDiffBetweenDates.md new file mode 100644 index 000000000..91e2bf16d --- /dev/null +++ b/snippets/getSecondsDiffBetweenDates.md @@ -0,0 +1,20 @@ +--- +title: getSecondsDiffBetweenDates +tags: date,beginner +--- + +Calculates the difference (in seconds) between two dates. + +- Subtract the two `Date` objects and divide by the number of milliseconds in a second to get the difference (in seconds) between them. + +```js +const getSecondsDiffBetweenDates = (dateInitial, dateFinal) => + (dateFinal - dateInitial) / 1000; +``` + +```js +getSecondsDiffBetweenDates( + new Date('2020-12-24 00:00:15'), + new Date('2020-12-24 00:00:17') +); // 2 +```