Class DateTime
DateTime is a complex data type representing a timestamp with both date and time elements 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.Examples
DateTime dt;
print(dt.toString());
Constructors
DateTime(DateTime)
Pass a value to copy into a new object.
Declaration
DateTime DateTime(DateTime value)
Examples
Date d;
Date next = Date(d);
printLine(next.toString());
Parameters
Type | Name | Description |
DateTime | value | DateTime object. |
Type | Description |
DateTime |
DateTime(Integer, Integer, Integer, Integer, Integer, Integer)
Specify all elements of a DateTime individually. It accepts 6 integer values, representing year, month (1-12), day-of-month (1-31), hour (0-23), minute (0-59), and second (0-59). The constructor automatically calculates the weekday.
Declaration
DateTime DateTime(Integer year, Integer month, Integer day, Integer hour, Integer min, Integer sec)
Examples
DateTime schoolEnds = DateTime(2020,06,22,11,0,0);
Parameters
Type | Name | Description |
Integer | year | The year portion of the timestamp. |
Integer | month | The month portion of the timestamp. |
Integer | mday | The day of month portion of the timestamp. |
Integer | hour | The hour portion of the timestamp. |
Integer | min | The minutes portion of the timestamp. |
Integer | sec | The seconds portion of the timestamp. |
Type | Description |
DateTime |
DateTime(String)
Pass a String containing date and time. The constructor will parse the text and create a DateTime object. Formats:
YYYY-MM-DD HH:MM:SS; YYYY-MM-DD HH:MM - automatically sets sec = 0; YYYYMMDDHHMMSS - mysql.timestamp; YYYY-MM-DD - automatically sets the time to 23:59:59 or 0:0:0 depending on endOfDay setting; an empty string or "0" - sets stamp to Jan 1. 1970 00:00:00 and isNull(); YYYY-MM-DD HH:MM:SS:XXXDeclaration
DateTime DateTime(String value)
Examples
DateTime graduation = DateTime("2020-06-22 11:00");
Parameters
Type | Name | Description |
String | value | A String containing a date (YYYY-MM-DD). |
Type | Description |
DateTime |
Methods
toString()
Converts a DateTime value to its string representation.
One of the most frequently used methods, typically when you are going to output something.Declaration
String toString()
Examples
DateTime dt;
printLine(dt.toString());
Returns
Type | Description |
String |
toString(String)
A variant of toString() that takes a string with one or more formatting codes. You can also include white-space and punctuation marks.
Declaration
String toString(String format)
Examples
DateTime dt;
printLine(dt.toString("HH12:MI2 AMPM"));
Parameters
Type | Name | Description |
String | format | A code for how to format the output. |
Returns
Type | Description |
String |
toString(String, String, String)
A variant of toString() that takes a string with one or more formatting codes. You can also include white-space and punctuation marks.
Declaration
String toString(String format, String months, String weekDays)
Examples
DateTime dt;
String days="søndag,mandag,tirsdag,onsdag,torsdag,fredag,lørdag";
printLine(dt.toString("WDAY uke ISOW1","",days));
Parameters
Type | Name | Description |
String | format | A code for how to format the output. |
String | months | A code for how to format the output. |
String | weekDays | A code for how to format the output. |
Returns
Type | Description |
String |
toString(Integer, Integer, Bool)
A variant of toString() that takes codes for mode and language as Integers and a boolean indicator for 12- or 24-hour clock.
Declaration
String toString(Integer mode, Integer language, Bool mode)
Examples
DateTime dt;
printLine(dt.toString(6,1,true));
Parameters
Type | Name | Description |
Integer | mode | 0-16. |
Integer | language | 0 = Norwegian; 1 = English; 2 = German; 3 = Swedish; 4 = Danish; 5 = Dutch |
Bool | mode | Indicator for 12- or 24-hour clock. True = 24h, false = 12h. |
Returns
Type | Description |
String |
addDay(Integer)
Adjusts the currently set date with the given number of days.
Declaration
DateTime addDay(Integer num)
Examples
DateTime dt;
dt.addDay(3);
Parameters
Type | Name | Description |
Integer | num | Number of days to add. |
Returns
Type | Description |
DateTime |
addMonth(Integer)
Adjusts the currently set date with the given number of months.
Declaration
DateTime addMonth(Integer num)
Examples
DateTime dt;
dt.addMonth(3);
Parameters
Type | Name | Description |
Integer | num | Number of months to add. |
Returns
Type | Description |
DateTime |
addYear(Integer)
Adjusts the currently set date with the given number of years.
Declaration
DateTime addYear(Integer num)
Examples
DateTime dt;
dt.addYear(1);
Parameters
Type | Name | Description |
Integer | num | Number of years to add. |
Returns
Type | Description |
DateTime |
addHour(Integer)
Adjusts the currently set date with the given number of hours.
Declaration
DateTime addHour(Integer num)
Examples
DateTime dt;
dt.addHour(3);
Parameters
Type | Name | Description |
Integer | num | Number of hours to add. |
Returns
Type | Description |
DateTime |
addMin(Integer)
Adjusts the currently set date with the given number of minutes.
Declaration
DateTime addMin(Integer num)
Examples
DateTime dt;
dt.addMin(30);
Parameters
Type | Name | Description |
Integer | num | Number of minutes to add. |
Returns
Type | Description |
DateTime |
addSec(Integer)
Adjusts the currently set date with the given number of seconds.
Declaration
DateTime addSec(Integer num)
Examples
DateTime dt;
dt.addSec(90);
Parameters
Type | Name | Description |
Integer | num | Number of seconds to add. |
Returns
Type | Description |
DateTime |
setTime(Time)
Sets the time-part of a DateTime by passing a Time object.
Declaration
Void setTime(Time theTime)
Examples
Time t;
DateTime dt;
dt.setTime(t);
Parameters
Type | Name | Description |
Time | theTime | The time to set. |
Returns
Type | Description |
DateTime |
getMDay()
Returns the day of the month as an Integer [1-31].
Declaration
Integer getMDay()
Examples
DateTime dt;
print(dt.getMDay().toString());
Returns
Type | Description |
Integer |
getMonth()
Returns the month as an Integer [1-12].
Declaration
Integer getMonth()
Examples
DateTime dt;
print(dt.getMonth().toString());
Returns
Type | Description |
Integer |
getWeek()
Returns the number of the week as an Integer [1-53].
Declaration
Integer getWeek()
Examples
DateTime dt;
print(dt.getWeek().toString());
Returns
Type | Description |
Integer |
getWeekDay()
Returns the day of the week as an Integer [0-6].
Declaration
Integer getWeekDay()
Examples
DateTime dt;
print(dt.getWeekDay().toString());
Returns
Type | Description |
Integer |
getYear()
Returns the year as an Integer.
Declaration
Integer getYear()
Examples
DateTime dt;
print(dt.getYear().toString());
Returns
Type | Description |
Integer |
getTime()
Returns the time-portion as a Time object.
Declaration
Time getTime()
Examples
DateTime dt;
Time t = dt.getTime();
print(t.toString());
Returns
Type | Description |
Time |
getDate()
Returns the date part of the DateTime
Declaration
Date getDate()
Examples
DateTime dt;
Date d = dt.getDate();
print(d.toString());
Returns
Type | Description |
Date |
diff(DateTime)
Returns the difference in the number of seconds between 2 timestamps. The method subtracts the passed timestamp from the DateTime object you invoke diff() on.
Declaration
Integer diff(DateTime value)
Examples
DateTime dt1;
DateTime dt2;
dt2.addHour(1);
print(dt1.diff(dt2).toString());
Parameters
Type | Name | Description |
DateTime | value | The timestamp to subtract from the DateTime object you invoked diff() on. |
Returns
Type | Description |
Integer | The number is negative if the input DateTime is the greatest. |
setUnix(Integer)
Sets the date and time to the number of the seconds since 01.01.1970 00:00:00.
Declaration
DateTime setUnix(Integer number)
Parameters
Type | Name | Description |
Integer | number | The number of the seconds since 01.01.1970 00:00:00. |
Returns
Type | Description |
DateTime |
getUnix()
Returns the date and time to the number of the seconds since 01.01.1970 00:00:00.
Declaration
Integer getUnix()
Returns
Type | Description |
Integer |
isNull()
Returns true if it has no value and false if it does.
Declaration
Bool isNull()
Examples
DateTime dt;
print(dt.isNull().toString());
Returns
Type | Description |
Bool |
moveToDayStart()
Moves the current DateTime to the start of the day, (00:00 o'clock). Returns a reference to itself.
Declaration
DateTime moveToDayStart()
Returns
Type | Description |
DateTime |
moveToHourStart()
Moves the current DateTime to the start of the current hour. Returns a reference to itself.
Declaration
DateTime moveToHourStart()
Returns
Type | Description |
DateTime |
moveToMonthStart()
Moves the current DateTime to the first second in the current month. Returns a reference to itself.
Declaration
DateTime moveToMonthStart()
Returns
Type | Description |
DateTime |
moveToQuarterStart()
Moves the current DateTime to the start of the current quarter (1. of January, 1. of April, 1. of July, or 1. of October). Returns a reference to itself.
Declaration
DateTime moveToQuarterStart()
Returns
Type | Description |
DateTime |
moveToWeekStart()
Moves the current DateTime back to 00:00:00 on monday in the current week. Returns a reference to itself.
Declaration
DateTime moveToWeekStart()
Returns
Type | Description |
DateTime |
moveToYearStart()
Moves the current DateTime to the first second in the current year. Returns a reference to itself.
Declaration
DateTime moveToYearStart()
Returns
Type | Description |
DateTime |
moveToDayEnd()
Moves the current DateTime to the end of the day (23:59:59). Returns a reference to itself.
Declaration
DateTime moveToDayEnd()
Returns
Type | Description |
DateTime |
moveToHourEnd()
Moves the current DateTime to the end of the current hour. Returns a reference to itself.
Declaration
DateTime moveToHourEnd()
Returns
Type | Description |
DateTime |
moveToMonthEnd()
Moves the current DateTime to the last second in the current month. Returns a reference to itself.
Declaration
DateTime moveToMonthEnd()
Returns
Type | Description |
DateTime |
moveToQuarterEnd()
Moves the current DateTime to the end of current quarter: 31. of Mars, 30. of June, 30 of September or 31. of December. Time is set to 23:59:59. Returns a reference to itself.
Declaration
DateTime moveToQuarterEnd()
Returns
Type | Description |
DateTime |
moveToWeekEnd()
Moves the current DateTime forward to 23:59:59 on Sunday of the current week. Returns a reference to itself.
Declaration
DateTime moveToWeekEnd()
Returns
Type | Description |
DateTime |
moveToYearEnd()
Moves the current DateTime to the last second in the current year. Returns a reference to itself.
Declaration
DateTime moveToYearEnd()
Returns
Type | Description |
DateTime |