Skip to main content
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.

Constructors

DateTime()

Default constructor.

DateTime(DateTime)

Pass a value to copy into a new object.

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.

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:XXX

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.
Returns: CRMScript.Global.String
If you do not want the name of the months and the days, use the toString-function with only one parameter, toString(String format)
Example:

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.
Returns: CRMScript.Global.String
Available codes: ISOW1, ISOW2, ISOWY2, ISOWY4, YY2, YY4, MM1, MM2, DD1, DD2, WEEKDAY, MONTH, WDAY, H24, HH24, H12, HH12, MI2, SS2. For details, see the CRMScript docs.
Example:

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.
Returns: CRMScript.Global.String
If you don’t include codes MONTH, WDAY, or both - use toString(String format) instead. If you include only 1 of them, send an empty string for the one you don’t use.Available codes: ISOW1, ISOW2, ISOWY2, ISOWY4, YY2, YY4, MM1, MM2, DD1, DD2, WEEKDAY, MONTH, WDAY, H24, HH24, H12, HH12, MI2, SS2. For details, see the CRMScript docs.
Example:

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.
Returns: CRMScript.Global.String

Modes:

Example:

addDay(Integer)

Adjusts the currently set date with the given number of days.
Returns: CRMScript.Global.DateTime Example:

addMonth(Integer)

Adjusts the currently set date with the given number of months.
Returns: CRMScript.Global.DateTime
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.
Example:

addYear(Integer)

Adjusts the currently set date with the given number of years.
Returns: CRMScript.Global.DateTime Example:

addHour(Integer)

Adjusts the currently set date with the given number of hours.
Returns: CRMScript.Global.DateTime Example:

addMin(Integer)

Adjusts the currently set date with the given number of minutes.
Returns: CRMScript.Global.DateTime Example:

addSec(Integer)

Adjusts the currently set date with the given number of seconds.
Returns: CRMScript.Global.DateTime Example:

setTime(Time)

Sets the time-part of a DateTime by passing a Time object.
Returns: CRMScript.Global.DateTime Example:

getMDay()

Returns the day of the month as an Integer [1-31].
Returns: CRMScript.Global.Integer Example:

getMonth()

Returns the month as an Integer [1-12].
Returns: CRMScript.Global.Integer Example:

getWeek()

Returns the number of the week as an Integer [1-53].
Returns: CRMScript.Global.Integer
See http://en.wikipedia.org/wiki/ISO_8601 for detailed info on ISO week numbers.
Example:

getWeekDay()

Returns the day of the week as an Integer [0-6].
Returns: CRMScript.Global.Integer
The 1st day of the week is Monday and has index 0!
Example:

getYear()

Returns the year as an Integer.
Returns: CRMScript.Global.Integer Example:

getTime()

Returns the time-portion as a Time object.
Returns: CRMScript.Global.Time Example:

getDate()

Returns the date part of the DateTime
Returns: CRMScript.Global.Date Example:

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.
Returns: CRMScript.Global.Integer - The number is negative if the input DateTime is the greatest. Example:

setUnix(Integer)

Sets the date and time to the number of the seconds since 01.01.1970 00:00:00.
Returns: CRMScript.Global.DateTime

getUnix()

Returns the date and time to the number of the seconds since 01.01.1970 00:00:00.
Returns: CRMScript.Global.Integer

isNull()

Returns true if it has no value and false if it does.
Returns: CRMScript.Global.Bool
A NULL/NUL/NIL DateTime is different from zero, in that it is conceptually without a value.
Example:

moveToDayStart()

Moves the current DateTime to the start of the day, (00:00 o’clock). Returns a reference to itself.
Returns: CRMScript.Global.DateTime

moveToHourStart()

Moves the current DateTime to the start of the current hour. Returns a reference to itself.
Returns: CRMScript.Global.DateTime

moveToMonthStart()

Moves the current DateTime to the first second in the current month. Returns a reference to itself.
Returns: CRMScript.Global.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.
Returns: CRMScript.Global.DateTime

moveToWeekStart()

Moves the current DateTime back to 00:00:00 on monday in the current week. Returns a reference to itself.
Returns: CRMScript.Global.DateTime

moveToYearStart()

Moves the current DateTime to the first second in the current year. Returns a reference to itself.
Returns: CRMScript.Global.DateTime

moveToDayEnd()

Moves the current DateTime to the end of the day (23:59:59). Returns a reference to itself.
Returns: CRMScript.Global.DateTime

moveToHourEnd()

Moves the current DateTime to the end of the current hour. Returns a reference to itself.
Returns: CRMScript.Global.DateTime

moveToMonthEnd()

Moves the current DateTime to the last second in the current month. Returns a reference to itself.
Returns: CRMScript.Global.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.
Returns: CRMScript.Global.DateTime

moveToWeekEnd()

Moves the current DateTime forward to 23:59:59 on Sunday of the current week. Returns a reference to itself.
Returns: CRMScript.Global.DateTime

moveToYearEnd()

Moves the current DateTime to the last second in the current year. Returns a reference to itself.
Returns: CRMScript.Global.DateTime