Skip to main content
Version: 7.9

dateDiff

This function is used by Ignition's Expression language.

Description

Calculates the difference between the two dates, returning the result as a floating point value in the units specified by field, which must be a string matching one of these values:

  • ms
  • second
  • sec
  • minute
  • min
  • hour
  • hr
  • day
  • week
  • month
  • year

The return value will be a floating point value, meaning that parts of units are considered. The exception to this rule is for the months and years fields, which will always return an integral difference. If the second date argument is after the first, the return value will be positive, otherwise it will be negative.

Syntax

dateDiff(date1, date2, field)

  • Parameters

    • Date date1 - The first date.

    • Date date2 - The second date.

    • string field - The units that the difference will be specified in.

  • Results

    • float - The difference between two dates in the units specified.

Examples

Code Snippet
dateDiff(toDate("2008-2-24 8:00:00"), toDate("2008-2-24 8:15:30"), "minute") //returns 15.5
Code Snippet
dateDiff(toDate("2008-2-24 8:00:00"), toDate("2008-3-12 9:28:00"), "month") //returns 1.0
Code Snippet
dateDiff(toDate("2008-2-24 8:00:00"), toDate("2008-3-12 9:28:00"), "day") //returns 17.02