datetime
The primary DateTime class that represents a date and time object in BoxLang
All temporal methods in BoxLang operate on this class and all castable date/time representations are cast to this class
Datetime Methods
bxDump(label=[string], depth=[numeric], maxRows=[numeric], top=[numeric], expand=[boolean], abort=[boolean], output=[string], format=[string], showUDFs=[boolean])
Outputs the contents of a variable (simple or complex) of any type for debugging purposes to a specific output location.
The available output locations are: - buffer: The output is written to the buffer, which is the default location. If running on a web server, the output is written to the browser. - console: The output is printed to the System console. - Absolute File Path The output is written to a file with the specified absolute file path.
The output format can be either HTML or plain text.
The default format is HTML if the output location is the buffer or a web server or a file, otherwise it is plain text for the console.
Method Signature
bxDump(label=[string], depth=[numeric], maxRows=[numeric], top=[numeric], expand=[boolean], abort=[boolean], output=[string], format=[string], showUDFs=[boolean])Arguments
label
string
false
A custom label to display above the dump (Only in HTML output)
depth
numeric
false
The recursion depth to display when dumping nested collections. 1-based: -1 (default) is unlimited, 0 shows nothing, 1 shows the top level with no recursion, 2 recurses once, etc. (Only in HTML output)
maxRows
numeric
false
The maximum number of keys/rows/items to display per level of a collection, array, or query. 1-based: -1 (default) is unlimited, 0 shows nothing, 1 shows a single row, etc. (Only in HTML output)
top
numeric
false
Deprecated: use maxRows instead. When maxRows is not also passed, top's value is used as maxRows. Kept for backwards compatibility with existing BoxLang code. (Only in HTML output)
expand
boolean
false
Whether to expand the dump. Be default, we try to expand as much as possible. (Only in HTML output)
true
abort
boolean
false
Whether to do a hard abort the request after dumping. Default is false
false
output
string
false
The output format which can be "buffer", "console", or "{absolute file path}". The default is "buffer".
format
string
false
The format of the output to a filename. Can be "html" or "text". The default is according to the output location.
showUDFs
boolean
false
Show UDFs or not. Default is true. (Only in HTML output)
true
compare(date2=[any], datepart=[string])
Compares the difference between two dates - returning 0 if equal, -1 if date2 is less than date1 and 1 if the inverse
Method Signature
compare(date2=[any], datepart=[string])Arguments
date2
any
true
The date which to compare against date1
datepart
string
false
The precision to compare down to. Accepts y, yyyy, m, d, h, n, s (default).
dateFormat(mask=[string], timezone=[string], locale=[string])
Formats a datetime, date or time
Method Signature
Arguments
mask
string
false
Optional format mask, or common mask. If an explicit mask is used, it should use the mask characters specified in the java.time.format.DateTimeFormatter class. If a common mask is used, the following are supported: - short: equivalent to "M/d/y h:mm tt" - medium: equivalent to "MMM d, yyyy h🇲🇲ss tt" - long: medium followed by three-letter time zone; i.e. "MMMM d, yyyy h🇲🇲ss tt zzz" - full: equivalent to "dddd, MMMM d, yyyy H🇲🇲ss tt zz" - ISO8601/ISO: equivalent to "yyyy-MM-dd'T'HH🇲🇲ssXXX" - epoch: Total seconds of a given date (Example:1567517664) - epochms: Total milliseconds of a given date (Example:1567517664000)
timezone
string
false
Optional specific timezone to apply to the date ( if not present in the date string )
locale
string
false
Optional ISO locale string which will be used to localize the resulting date/time string
dateTimeFormat(mask=[string], timezone=[string], locale=[string])
Formats a datetime, date or time
Method Signature
Arguments
mask
string
false
Optional format mask, or common mask. If an explicit mask is used, it should use the mask characters specified in the java.time.format.DateTimeFormatter class. If a common mask is used, the following are supported: - short: equivalent to "M/d/y h:mm tt" - medium: equivalent to "MMM d, yyyy h🇲🇲ss tt" - long: medium followed by three-letter time zone; i.e. "MMMM d, yyyy h🇲🇲ss tt zzz" - full: equivalent to "dddd, MMMM d, yyyy H🇲🇲ss tt zz" - ISO8601/ISO: equivalent to "yyyy-MM-dd'T'HH🇲🇲ssXXX" - epoch: Total seconds of a given date (Example:1567517664) - epochms: Total milliseconds of a given date (Example:1567517664000)
timezone
string
false
Optional specific timezone to apply to the date ( if not present in the date string )
locale
string
false
Optional ISO locale string which will be used to localize the resulting date/time string
day(timezone=[string], locale=[string])
Returns the day of the month of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
dayOfWeek(timezone=[string], locale=[string])
Returns the numeric day of the week of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
dayOfWeekAsString(timezone=[string], locale=[string])
Returns the full day of the week name of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
dayOfWeekShortAsString(timezone=[string], locale=[string])
Returns the short day of the week name of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
dayOfYear(timezone=[string], locale=[string])
Returns the numeric day of the year of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
daysInMonth(timezone=[string], locale=[string])
Returns the number of days in the month of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
daysInYear(timezone=[string], locale=[string])
Return the number of days in the year of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
diff(datepart=[string], date2=[any])
Returns the numeric difference in the requested date part between two dates
Method Signature
Arguments
datepart
string
true
The datepart code in which to express the difference (yyyy, q, m, d, y, w, ww, wd, h, n, s, l).
date2
any
true
The date which to compare against date1
firstDayOfMonth(timezone=[string], locale=[string])
Returns the first date of the month of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
format(mask=[string], timezone=[string], locale=[string])
Formats a datetime, date or time
Method Signature
Arguments
mask
string
false
Optional format mask, or common mask. If an explicit mask is used, it should use the mask characters specified in the java.time.format.DateTimeFormatter class. If a common mask is used, the following are supported: - short: equivalent to "M/d/y h:mm tt" - medium: equivalent to "MMM d, yyyy h🇲🇲ss tt" - long: medium followed by three-letter time zone; i.e. "MMMM d, yyyy h🇲🇲ss tt zzz" - full: equivalent to "dddd, MMMM d, yyyy H🇲🇲ss tt zz" - ISO8601/ISO: equivalent to "yyyy-MM-dd'T'HH🇲🇲ssXXX" - epoch: Total seconds of a given date (Example:1567517664) - epochms: Total milliseconds of a given date (Example:1567517664000)
timezone
string
false
Optional specific timezone to apply to the date ( if not present in the date string )
locale
string
false
Optional ISO locale string which will be used to localize the resulting date/time string
getnumericdate(timezone=[string], locale=[string])
Returns the numeric date in days from epoch of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
hash(algorithm=[string], encoding=[string], numIterations=[integer])
Creates an algorithmic hash of an object
Method Signature
Arguments
algorithm
string
false
The supported java.security.MessageDigest algorithm (case-insensitive) or "quick" for an insecure 64-bit hash
MD5
encoding
string
false
Applicable to strings ( default "utf-8" )
utf-8
numIterations
integer
false
The number of iterations to re-digest the object ( default 1 );
1
hour(timezone=[string], locale=[string])
Returns the hour of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
millisecond(timezone=[string], locale=[string])
Returns the millisecond of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
minute(timezone=[string], locale=[string])
Returns the minute of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
month(timezone=[string], locale=[string])
Returns the numeric month of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
monthAsString(timezone=[string], locale=[string])
Returns the full month name of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
monthShortAsString(timezone=[string], locale=[string])
Returns the short month name of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
nanosecond(timezone=[string], locale=[string])
Returns the nanosecond of adate object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
offset(timezone=[string], locale=[string])
Returns the timezone offset of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
quarter(timezone=[string], locale=[string])
Returns the quarter of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
second(timezone=[string], locale=[string])
Returns the second of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
setDay(value=[integer])
Sets a single date/time unit on a date object, mutating it in place and returning it.
Out-of-range values roll over (e.g. setDay( 50 ) advances into following months) while zero/negative values clamp to the first valid unit (e.g. setDay( 0 ) becomes day 1).
Method Signature
Arguments
value
integer
true
The value to set for the given date/time unit
setHour(value=[integer])
Sets a single date/time unit on a date object, mutating it in place and returning it.
Out-of-range values roll over (e.g. setDay( 50 ) advances into following months) while zero/negative values clamp to the first valid unit (e.g. setDay( 0 ) becomes day 1).
Method Signature
Arguments
value
integer
true
The value to set for the given date/time unit
setMinute(value=[integer])
Sets a single date/time unit on a date object, mutating it in place and returning it.
Out-of-range values roll over (e.g. setDay( 50 ) advances into following months) while zero/negative values clamp to the first valid unit (e.g. setDay( 0 ) becomes day 1).
Method Signature
Arguments
value
integer
true
The value to set for the given date/time unit
setMonth(value=[integer])
Sets a single date/time unit on a date object, mutating it in place and returning it.
Out-of-range values roll over (e.g. setDay( 50 ) advances into following months) while zero/negative values clamp to the first valid unit (e.g. setDay( 0 ) becomes day 1).
Method Signature
Arguments
value
integer
true
The value to set for the given date/time unit
setSecond(value=[integer])
Sets a single date/time unit on a date object, mutating it in place and returning it.
Out-of-range values roll over (e.g. setDay( 50 ) advances into following months) while zero/negative values clamp to the first valid unit (e.g. setDay( 0 ) becomes day 1).
Method Signature
Arguments
value
integer
true
The value to set for the given date/time unit
setYear(value=[integer])
Sets a single date/time unit on a date object, mutating it in place and returning it.
Out-of-range values roll over (e.g. setDay( 50 ) advances into following months) while zero/negative values clamp to the first valid unit (e.g. setDay( 0 ) becomes day 1).
Method Signature
Arguments
value
integer
true
The value to set for the given date/time unit
timeFormat(mask=[string], timezone=[string], locale=[string])
Formats a datetime, date or time
Method Signature
Arguments
mask
string
false
Optional format mask, or common mask. If an explicit mask is used, it should use the mask characters specified in the java.time.format.DateTimeFormatter class. If a common mask is used, the following are supported: - short: equivalent to "M/d/y h:mm tt" - medium: equivalent to "MMM d, yyyy h🇲🇲ss tt" - long: medium followed by three-letter time zone; i.e. "MMMM d, yyyy h🇲🇲ss tt zzz" - full: equivalent to "dddd, MMMM d, yyyy H🇲🇲ss tt zz" - ISO8601/ISO: equivalent to "yyyy-MM-dd'T'HH🇲🇲ssXXX" - epoch: Total seconds of a given date (Example:1567517664) - epochms: Total milliseconds of a given date (Example:1567517664000)
timezone
string
false
Optional specific timezone to apply to the date ( if not present in the date string )
locale
string
false
Optional ISO locale string which will be used to localize the resulting date/time string
timezone(timezone=[string], locale=[string])
Provides the BIF and member functions for all time unit request with no arguments
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
week(timezone=[string], locale=[string])
Returns the numeric week within a year of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
year(timezone=[string], locale=[string])
Returns the year of a date object. If a string is provided as the argument, an attempt will be made to parse it as a date. If parsing fails, an error will be thrown.
Method Signature
Arguments
timezone
string
false
An optional timezone which to convert the date object to
locale
string
false
An optional ISO locale string which will return the specified time unit with a locale-specific result ( e.g. month name, or starting day of week as Monday vs Sunda )
Last updated
Was this helpful?
