Show / Hide Table of Contents

Class Date

Date is a complex data type representing a day, month, and year on ISO format YYYY-MM-DD. The default value is now.

Before a Date is initialized, it has no value. This is commonly written as NULL, NUL, or NIL in other programming languages. CRMScript automatically initializes Date objects when declared to the current date. Thus this situation is uncommon.
Syntax
Examples
Date d;
print(d.toString());

Constructors

Date()

Default constructor.

Declaration
Date Date()
Returns
Type Description
Date
Remarks

The default value is now.

Examples
Date d;
print(d.toString());

Date(Date)

Pass a value to copy into a new object.

Declaration
Date Date(Date value)
Parameters
Type Name Description
Date value

Date object.

Returns
Type Description
Date
Remarks

The default value is now.

Examples
Date d;
Date next = Date(d);
printLine(next.toString());

Date(String)

Pass a String containing a date on format YYYY-MM-DD. The constructor will parse the text and create a Date object.

Declaration
Date Date(String value)
Parameters
Type Name Description
String value

A String containing a date (YYYY-MM-DD).

Returns
Type Description
Date
Remarks

The default value is now.

Examples
String newYearsDay = "2020-01-01";
Date q1 = Date(newYearsDay);

Methods

addDay(Integer)

Adjusts the currently set date with the given number of days. The original object will be modified, and a copy is returned.

Declaration
Date addDay(Integer num)
Parameters
Type Name Description
Integer num

Number of days to add.

Returns
Type Description
Date
Remarks

If the number is negative, the days are subtracted.

Examples
Date d;
d.addDay(3);
printLine("Three days from now: " + d.toString());

addMonth(Integer)

Adjusts the currently set date with the given number of months.

Declaration
Date addMonth(Integer num)
Parameters
Type Name Description
Integer num

Number of months to add.

Returns
Type Description
Date
Remarks

The day remains unchanged regardless of the number of days in the months added or subtracted. However, if the update would result in February 29th in a year that is not a leap year, CRMScript automatically corrects it to March 1st.

Examples
Date d;
d.addMonth(3);
printLine("Three months from now: " + d.toString());

addYear(Integer)

Adjusts the currently set date with the given number of years.

Declaration
Date addYear(Integer num)
Parameters
Type Name Description
Integer num

Number of years to add.

Returns
Type Description
Date
Remarks

The original object will be modified, and a copy is returned.

Examples
Date d;
d.addYear(1);
printLine("A year from now: " + d.toString());

getMDay()

Returns the day of the month as an Integer [1-31].

Declaration
Integer getMDay()
Returns
Type Description
Integer
Examples
Date d;
print(d.getMDay().toString());

getMonth()

Returns the month as an Integer [1-12].

Declaration
Integer getMonth()
Returns
Type Description
Integer
Examples
Date d;
print(d.getMonth().toString());

getWeek()

Returns the ISO number of the week as an Integer [1-53].

Declaration
Integer getWeek()
Returns
Type Description
Integer
Remarks

See http://en.wikipedia.org/wiki/ISO_8601 for detailed info on ISO week numbers.

Examples
Date d;
print(d.getWeek().toString());

getWeekDay()

Returns the ISO day of the week as an Integer [0-6].

Declaration
Integer getWeekDay()
Returns
Type Description
Integer
Remarks

The 1st day of the week is Monday and has index 0!

Examples
Date d;
print(d.getWeekDay().toString());

getYear()

Returns the year as an Integer.

Declaration
Integer getYear()
Returns
Type Description
Integer
Examples
Date d;
print(d.getYear().toString());

isNull()

Returns true if it has no value and false if it does.

Declaration
Bool isNull()
Returns
Type Description
Bool
Remarks

A NULL/NUL/NIL Date is different from zero, in that it is conceptually without a value.

Examples
Date d;
print(d.isNull().toString());

toString()

Converts a date value to its string representation, in ISO format.

Declaration
String toString()
Returns
Type Description
String
Remarks

One of the most frequently used methods, typically when you are going to output something.

Examples
Date d;
String s = d.toString();
In This Article
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top