Skip to main content
Version: 7.9

dateExtract

This function is used by Ignition's Expression language.

Description

Returns an integer value that is the value of the specified date field within the given date. The field must be a string, and must match one of these values:

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

Months are returned zero-indexed. That is, January is month 0, February is month 1, and so on. If this is inconvenient for you - just add one to the results.

Syntax

dateExtract(date, field)

  • Parameters

    • Date date - The given date.

    • string field - The field to extract the value from.

  • Results

    • int - The value of the specified field within the given date.

Examples

Code Snippet
dateExtract(toDate("2003-9-14 8:00:00"), "year") //returns 2003
Code Snippet
dateExtract(toDate("2009-1-15 8:00:00"), "month") //returns 0
Code Snippet
dateExtract(toDate("2008-1-24 8:00:00"), "month") + 1 //returns 1