Skip to main content
NICE CXone Expert

We will be updating our infrastructure on Dec 2, 2023. Sites will be down starting at 8pm Pacific time. This may last up to 3 hours.

Expert Success Center

Date functions

Date functions available in the DekiScript and MindTouch runtime environment.

Add time

date.adddays(datetime, days) : str - add days to date-time.

Name Type Description
datetime str date time string
days num days to add

Example: Determine the date 7 days before now and format it.

var now = date.now;
var weekago = date.adddays(now,-7);
let weekago = date.format(weekago, "yyyy-MM-dd");
weekago;

date.addhours(datetime, hours) : str - add hours to date-time.

Name Type Description
datetime str date time string
hours num hours to add

Example: Determine the time 12 hours in the future and format it.

var now = date.now;
var later = date.addHours(now,12);
let later = date.format(later, "HH:mm");
later;

date.addminutes(datetime, minutes) : str - add minutes to date-time.

Name Type Description
datetime str date time string
minutes num minutes to add

date.addmonths(datetime, months) : str - add months to date-time.

Name Type Description
datetime str date time string
months num months to add

date.addseconds(datetime, seconds) : str - add seconds to date-time.

Name Type Description
datetime str date time string
seconds num seconds to add

date.addweeks(datetime, weeks) : str - add weeks to date-time.

Name Type Description
datetime str date time string
weeks num weeks to add

date.addyears(datetime, years) : str - add years to date-time.

Name Type Description
datetime str date time string
years num years to add

Get time

date.day(datetime) : str - get day of month from date-time.

Name Type Description
datetime str date time string

date.dayname(datetime) : str - get name of day from date-time.

Name Type Description
datetime str date time string

date.dayofweek(datetime) : num - get day of the week from date-time.

Name Type Description
datetime str date time string

date.dayofyear(datetime) : num - get day of the year from date-time.

Name Type Description
datetime str date time string

date.daysinmonth(datetime) : num - get the number of days in date-time month.

Name Type Description
datetime str date time string

date.hours(datetime) : num - get the hours component of date-time.

Name Type Description
datetime str date time string

date.week(datetime) : num - get week of year from date-time.

Name Type Description
datetime str date time string

date.year(datetime) : str - get 4-digit year from date-time.

Name Type Description
datetime str date time string

date.calendar(datetime, firstday) : list - get list of calendar days for date-time month.

Name Type Description
datetime str date time string
firstday num (optional) first day of the week (one of 0 = Sunday, 1 = Monday, etc.; default: 0)

Example: Loop over a list of days in the current month.

var now = date.now;
<ul>
foreach (var month in date.calendar(now))
{
    foreach (var week in month)
    {
        // web.pre(week);         // Uncomment the web.pre function to see the week output
        <li>"The " .. week.dayofyear .. " day of the year is " .. week.dayname</li>
    }
}
</ul>

date.minutes(datetime) : num - get the minutes component of date-time.

Name Type Description
datetime str date time string

date.month(datetime) : str - get 2-digit month from date-time.

Name Type Description
datetime str date time string

date.monthname(datetime) : str - get name of the month from date-time.

Name Type Description
datetime str date time string

date.seconds(datetime) : num - get the seconds component of date-time.

Name Type Description
datetime str date time string

date.startofday(datetime) : str - get date-time corresponding to beginning of day (i.e. midnight).

Name Type Description
datetime str date time string

date.startofmonth(datetime) : str - get date-time corresponding to beginning of month.

Name Type Description
datetime str date time string

date.startofweek(datetime) : str - get date-time corresponding to beginning of week (Sunday).

Name Type Description
datetime str date time string

date.startofyear(datetime) : str - get date-time corresponding to beginning of year.

Name Type Description
datetime str date time string

date.time(datetime) : str - get time from date-time.

Name Type Description
datetime str date time string

date.timezone(datetime, default) : str - get the time-zone component of date-time.

Name Type Description
datetime str date time string
default str (optional) default timezone (default: GMT)

Compute time

date.diffdays(first, second) : num - compute the difference between the first and second date-time in days.

Name Type Description
first str first date time string
second str second date time string

date.diffhours(first, second) : num - compute the difference between the first and second date-time in hours.

Name Type Description
first str first date time string
second str second date time string

date.diffminutes(first, second) : num - compute the difference between the first and second date-time in minutes.

Name Type Description
first str first date time string
second str second date time string

date.diffmonths(first, second) : num - compute the difference between the first and second date-time in months.

Name Type Description
first str first date time string
second str second date time string

date.diffseconds(first, second) : num - compute the difference between the first and second date-time in seconds.

Name Type Description
first str first date time string
second str second date time string

Check if time

date.inrange(datetime, lower, upper, dateonly) : bool - check if date-time occurs between lower and upper date-time, inclusive.

Name Type Description
datetime str date time to check
lower str lower bound for date time
upper str upper bound for date time
dateonly bool (optional) check if the date-time falls within the date range, ignoring time-of-day

date.isafter(first, second) : bool - check if first date-time is after second date-time.

Name Type Description
first str first date time string
second str second date time string

date.isbefore(first, second) : bool - check if first date-time is before second date-time.

Name Type Description
first str first date time string
second str second date time string

date.issameday(first, second) : bool - check if first date-time and the second date-time fall on the same day.

Name Type Description
first str first date time string
second str second date time string

date.issamemonth(first, second) : bool - check if first date-time and the second date-time fall on the same month.

Name Type Description
first str first date time string
second str second date time string

date.issameweek(first, second) : bool - check if first date-time and the second date-time fall on the same week.

Name Type Description
first str first date time string
second str second date time string

date.isvalid(datetime) : bool - check if the string is a valid date-time.

Name Type Description
datetime str (optional) date time string

Compare time

date.max(first, second) : str - compare the first date-time to the second date-time and return the later one.

Name Type Description
first str first date time string
second str second date time string

date.min(first, second) : str - compare the first date-time to the second date-time and return the earlier one.

Name Type Description
first str first date time string
second str second date time string

date.compare(first, second) : num - compare the first date-time to the second date-time.

Name Type Description
first str first date time string
second str second date time string

Create or parse time

date.new(year, month, day, hour, minute, second, timezone) : str - create new date-time value.

Name Type Description
year num Year value
month num Month value (1-12)
day num Day value (1-31)
hour num (optional) Hour value (0-23, default: 0)
minute num (optional) Minute value (0-59, default: 0)
second num (optional) Second value (0-59, default: 0)
timezone str (optional) time-zone offset (format: ±hh:mm, default: GMT)

date.parse(text, format, culture, timezone) : str - parse a custom date-time string.

Name Type Description
text str text to parse
format str (optional) custom date formatting string: see http://msdn2.microsoft.com/EN-US/lib.../az4se3k1.aspx (default: best effort parsing)
culture str (optional) culture code (default: page or site culture)
timezone str (optional) timezone offset to use, if none given in the date (format: ±hh:mm, default: GMT)

date.parseisoweek(isoweekdate) : str - parse an ISO 8601 week-date string. (http://en.wikipedia.org/wiki/ISO_8601)

Name Type Description
isoweekdate str full ISO 8601 week string (e.g. "yyyy-Www-d")

Current

date.now : str - current date-time in GMT format.

date.now;  // Parenthesis should not be used

date.timezonenow(timezone) : str - current date-time in time-zone format.

Name Type Description
timezone str (optional) time-zone offset (format: ±hh:mm, default: GMT)

Beginning

date.timezonetoday(timezone) : str - beginning of day for GMT timezone.

Name Type Description
timezone str (optional) time-zone offset (format: ±hh:mm, default: GMT)

date.today() : str - beginning of day for GMT timezone.

Decompose or show only time

date.parts(datetime) : map - decompose a date-time into its components parts.

Name Type Description
datetime str date time string

date.date(datetime) : str - show only date component of date-time.

Name Type Description
datetime str date time string

Covert or change time

date.isoweek(datetime) : map - convert date-time into ISO 8601 week-date values. (http://en.wikipedia.org/wiki/ISO_8601)

Name Type Description
datetime str date time string

date.changetimezone(datetime, timezone) : str - change time-zone of date-time.

datetime

Name Type Description
str date time string
timezone str (optional) time-zone offset (format: ±hh:mm, default: GMT)
  • Was this article helpful?