timespan

Modified on Thu, 9 Jul at 10:49 AM

timespan

TABLE OF CONTENTS

Calculate the difference between two dates

Definition

string timespan(datetime $first, datetime $second, string $format, string $culture)

Calculates the difference between the two dates and formats the output using standard timespan formatting.

Parameters

datetime $first

The first date to be used in the calculation.

datetime $second

The second date to be used in the calculation.

string $format

The timespan format to be used for showing the output of the calculation.

string $culture

The culture to be used for the output. If no culture is specified, then invariant culture is used.

Returns

string

A formatted string containing the time difference between the two dates.

Examples

Transformation
{
    a: timespan(to_datetime('2020-11-20 00:00:00Z', '', 'en-US'), to_datetime('2025-06-23 00:00:00Z', '', 'en-US'), 'g', 'en-US'),
    b: timespan(to_datetime('2025-11-23 02:00:00Z', '', 'en-US'), to_datetime('2025-11-23 06:00:00Z', '', 'en-US'), 'c', 'en-US')
}
Result
{
  "a": "1676:0:00:00",
  "b": "04:00:00"
}


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article