diffBetweenDates

Type:Function
Status:stable
Since:1.0.0
Platform:jsnode
@blackbyte.sugar.shared.datetime

This function allows you to get the difference between two date strings. It will returns you an object with the difference represented with these properties (years, months, days, hours, minutes, seconds). Under the hood, it make uses of the wonderful Luxon library.

Params

  1. date*-String

    The date string to parse

  2. settings{}TDiffBetweenDatesSettings

    Some settings to configure your parsing

Return

  1. -Date

    The `Date` instance representing your date string

Example

import { diffBetweenDates } from '@blackbyte/sugar/datetime';
diffBetweenDates('1945-10-12', '2025-10-15');

Settings

  1. formatString

    If you know the format of your date string, you can pass it here. This will make the parsing faster and more reliable. See Luxon documentation for the list of supported tokens.