You can create arrays of any data type to store more than one value at the same time like this:
String[] s1;. For a given array, all items must be of the same type. Read more about looping and accessing array items in the fundamentals section.Constructors
DateTime DateTime(DateTime dt)
Pass aDateTime object to copy into a new object.
DateTime DateTime(Integer year, Integer month, Integer mday, Integer hour, Integer min, Integer sec)
Specify all elements of a DateTime individually. The constructor automatically calculates the weekday.DateTime DateTime(String p0)
Pass aString containing date and time on the format of one of the listed formats. The constructor will parse the text and create a DateTime object.
- 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
Timestamps as strings
String toString()
toString() is one of the most frequently used methods, typically when you are going to output something. It returns a string representation of a DateTime object using standard formatting.
String toString(String format)
A variant oftoString() that takes a string with formatting codes. You can also include white-space and punctuation marks.
String toString(String format, String months, String weekDays)
A variant oftoString() that takes a string with formatting codes plus comma-separated lists of month and weekday names in your preferred language.
toString(String format) instead. If you include only 1 of them, send an empty string for the one you don’t use.
String toString(Integer mode, Integer language, Bool 24HourMode)
A variant oftoString() that takes codes for mode and language as Integers and a boolean indicator for 12- or 24-hour clock.
- true: use time in 24-hour mode
- false: use time in 12-hour mode
toString() without arguments, but with the month as a 3-letter abbreviation.
Mode: [0-16], see end of this section
Try the following snippet to view output of all modes.
Setting and updating date and time
Date and time values are set relative to when the DateTime object was created.- A positive increment indicates sometime in the future.
- A negative value indicates sometime in the past.
DateTime addDay(Integer num)
addDay() will adjust the currently set date with the given number of days.
The parameter granularity is days.
DateTime addMonth(Integer num)
addMonth() will adjust the currently set date with the given number of months.
The parameter granularity is months.
DateTime addYear(Integer num)
addYear() will adjust the currently set date with the given number of years.
The parameter granularity is years.
DateTime addHour(Integer num)
addHour() will adjust the currently set time with the given number of hours.
The parameter granularity is hours.
DateTime addMin(Integer num)
addMin() will adjust the currently set time with the given number of minutes.
The parameter granularity is minutes.
DateTime addSec(Integer num)
addSec() will adjust the currently set time with the given number of seconds.
The parameter granularity is days.
Void setTime(Time theTime)
setTime() sets the time-part of a DateTime by passing a Time object.
Retrieving date and time details
Integer getMDay()
getMDay() returns the day of the month as an Integer [1-31].
Integer getMonth()
getMonth() returns the month as an Integer [1-12].
Integer getWeek()
getWeek() returns the number of the week as an Integer [1-53].
Integer getWeekDay()
getWeekDay() returns the day of the week as an Integer [0-6].
Integer getYear()
getYear() returns the year as an Integer.
Time getTime()
getTime() returns the time-portion as a Time object.
Date getDate()
getDate() returns the date part of the DateTime
Comparing timestamps
Integer diff(DateTime otherDateTime)
diff() 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.
dt1 < dt2 means that dt1 comes before dt2 in chronological time.
UNIX time
For when you need to convert between SuperOffice and integrated systems running on UNIX time.DateTime setUnix(Integer number)
setUnix() sets the date and time to the number of the seconds since 01.01.1970 00:00:00.
Integer getUnix()
getUnix() returns the number of seconds since 01.01.1970 00:00:00.
No value
Before a DateTime is initialized, it has no value. This is commonly written as NULL, NUL, or NIL in other programming languages. CRMScript automatically initializes DateTime objects when declared to the current timestamp. Thus this situation is uncommon. However, it is a good habit to always test that you have a value before using it.Bool isNull()
isNull() will return true if it has no value and false if it does.
Formatting options
Week numbers and year
Month and day
Time
AMPM returns either am or pm.
Modes
Remarks:
- 12 is HTTP-date
- 13 is SOAP standard formatting