mazey
    Preparing search index...

    Function getDateDifference

    • Calculate the interval between two dates or timestamps.

      The default d type returns the number of whole days. The text type returns an English duration using days, hours, minutes, and seconds while omitting zero-valued units. A zero interval returns "0 seconds". Any other type returns the number of whole seconds. Negative intervals and invalid dates return an empty string.

      Usage:

      import { getDateDifference } from "mazey";

      const days = getDateDifference(0, 90061000);
      const text = getDateDifference(0, 90061000, { type: "text" });
      const compactText = getDateDifference(0, 90060000, { type: "text" });
      const dateStringDays = getDateDifference(
      "2020-03-28 00:09:27",
      "2023-04-18 10:54:00"
      );
      console.log(days);
      console.log(text);
      console.log(compactText);
      console.log(dateStringDays);

      Output:

      1
      1 day 1 hour 1 minute 1 second
      1 day 1 hour 1 minute
      1116
      

      Parameters

      • start: string | number | Date = 0

        Start date or timestamp.

      • end: string | number | Date = 0

        End date or timestamp.

      • options: { type?: string } = defaultGetDateDifferenceOptions

        Formatting options. Use d for whole days or text for an English duration.

      Returns string | number

      Whole days, whole seconds, an English duration, or an empty string for a negative or invalid interval.

      Strings in YYYY-MM-DD HH:mm:ss format are normalized and parsed as local time. Other date strings use the runtime's native Date parser; use timestamps or ISO strings with an explicit timezone when parsing must be portable.