InvariantDate

JSON object that stores a date in a culture-invariant format.

NOTE  
Starting with v. 22.1.5, invariant dates are immutable, so the method no longer updates the instance with the new value. If you need to store the new value, you need to assign it to a new invariant date variable.

Syntax

class InvariantDate(inputDate)
 
Parameter Description
inputDate Date object or string representing a date. Eg:
  • InvariantDate(2019, 10, 20)
  • InvariantDate("2019-10-20")
  • InvariantDate("2019-10-20T13:45:43") (the time information is ignored)

Return Value

Returns a JSON object that contains the date in culture-invariant format (in the form: {"invariantDate":"2020-01-23"}).

Properties

Property Returned Type

Description

day number The day component of the date, expressed as a value between 1 and 31.
dayOfWeek number The day of the week, expressed as a value between 1 (Monday) and 7 (Sunday).
dayOfYear number The day of the year, expressed as a value between 1 and 366.
weekofYear number The week of the year, expressed as a value between 1 and 366.
isEmpty boolean Returns True if the variable is empty and False if it has a value assigned.
month number The month component of the date, expressed as a value between 1 and 12.
today InvariantDate The current date.
year number The year component of the date.

Methods

Method Returned Type

Description

addDays(number) InvariantDate

Adds the specified number of days to the value of the instance. Starting with v. 22.1.5, the method returns a new invariant date value. Negative values subtract the specified number of days (dates prior to 0001-01-01 are not supported).

addMonths(number) InvariantDate

Adds the specified number of months to the value of the instance. Starting with v. 22.1.5, the method returns a new invariant date value. Negative values subtract the specified number of months (dates prior to 0001-01-01 are not supported).

NOTE  
The day component of the date is "rounded down". For instance, adding one month to 2020-03-31 will return 2020-04-30.
addYears(number) InvariantDate

Adds the specified number of years to the value of the instance and returns the instance. Starting with v. 22.1.5, the method returns a new invariant date value. Negative values subtract the specified number of years (dates prior to 0001-01-01 are not supported).

NOTE  
The day component of the date is "rounded down". For instance, adding one year to 2020-02-29 will return 2021-02-28.
toDateTime() Date Returns a date representation of the instance's value. The time will be set to 12:00:00 AM.
toString() string Returns a string representation of the instance's value in "yyyy-mm-dd" format.
getEndOfMonth(date: InvariantDate)v21.2 and later InvariantDate Returns an invariant date matching the last day from the month of the input date.
dateDiff(datePart: string, startDate: InvariantDate, endDate: InvariantDate)v21.2 and later number Returns the number of days, weeks, months, quarters, or years between the startDate and endDate, depending on the datePart parameter. Supported values for the datePart parameter are: "Day", "Week", "Month", "Quarter", and "Year".

Examples